Upgrade rust/crates/pin-project-internal to 1.0.7 am: e20c266df7

Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/pin-project-internal/+/1713029

Change-Id: Ic5019dfbdf9e7e1f7d0c009a45448a50215601d8
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 6cfdedc..51b8b66 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
 {
   "git": {
-    "sha1": "a51d39fcdb31fe78cc61c0053ead2beb65a4156d"
+    "sha1": "c110ce7bc8ad8473c735f8a2f8b4ca0f8bd4b315"
   }
 }
diff --git a/Android.bp b/Android.bp
index d84760b..7dfb19c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -71,5 +71,5 @@
 // dependent_library ["feature_list"]
 //   proc-macro2-1.0.26 "default,proc-macro"
 //   quote-1.0.9 "default,proc-macro"
-//   syn-1.0.68 "clone-impls,default,derive,full,parsing,printing,proc-macro,quote,visit-mut"
-//   unicode-xid-0.2.1 "default"
+//   syn-1.0.72 "clone-impls,default,derive,full,parsing,printing,proc-macro,quote,visit-mut"
+//   unicode-xid-0.2.2 "default"
diff --git a/Cargo.toml b/Cargo.toml
index 83d10cd..35aa262 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
 [package]
 edition = "2018"
 name = "pin-project-internal"
-version = "1.0.6"
+version = "1.0.7"
 authors = ["Taiki Endo <te316e89@gmail.com>"]
 description = "Implementation detail of the `pin-project` crate.\n"
 documentation = "https://docs.rs/pin-project-internal"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 707c32b..71fc35a 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
 [package]
 name = "pin-project-internal"
-version = "1.0.6"
+version = "1.0.7"
 authors = ["Taiki Endo <te316e89@gmail.com>"]
 edition = "2018"
 license = "Apache-2.0 OR MIT"
diff --git a/METADATA b/METADATA
index 381f041..5581c75 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/pin-project-internal/pin-project-internal-1.0.6.crate"
+    value: "https://static.crates.io/crates/pin-project-internal/pin-project-internal-1.0.7.crate"
   }
-  version: "1.0.6"
+  version: "1.0.7"
   license_type: NOTICE
   last_upgrade_date {
     year: 2021
-    month: 4
-    day: 1
+    month: 5
+    day: 19
   }
 }
diff --git a/src/lib.rs b/src/lib.rs
index 3e908b6..d14228d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,7 +9,7 @@
 ))]
 #![warn(unsafe_code)]
 #![warn(future_incompatible, rust_2018_idioms, single_use_lifetimes, unreachable_pub)]
-#![warn(clippy::all, clippy::default_trait_access)]
+#![warn(clippy::default_trait_access)]
 #![allow(clippy::needless_doctest_main)]
 
 // older compilers require explicit `extern crate`.
diff --git a/src/pin_project/derive.rs b/src/pin_project/derive.rs
index 82539ca..7dc1ba5 100644
--- a/src/pin_project/derive.rs
+++ b/src/pin_project/derive.rs
@@ -3,7 +3,7 @@
 use syn::{
     parse_quote, token, visit_mut::VisitMut, Attribute, Data, DataEnum, DeriveInput, Error, Field,
     Fields, FieldsNamed, FieldsUnnamed, Generics, Ident, Index, Lifetime, LifetimeDef, Meta,
-    MetaList, NestedMeta, Result, Token, Type, Variant, Visibility, WhereClause,
+    MetaList, MetaNameValue, NestedMeta, Result, Token, Type, Variant, Visibility, WhereClause,
 };
 
 use super::{
@@ -152,7 +152,7 @@
     /// The projected types.
     proj: ProjectedType,
     /// Types of the pinned fields.
-    pinned_fields: Vec<Type>,
+    pinned_fields: Vec<&'a Type>,
     /// Kind of the original type: struct or enum
     kind: TypeKind,
 
@@ -320,13 +320,13 @@
     }
 }
 
-fn parse_struct(
-    cx: &mut Context<'_>,
-    fields: &Fields,
+fn parse_struct<'a>(
+    cx: &mut Context<'a>,
+    fields: &'a Fields,
     generate: &mut GenerateTokens,
 ) -> Result<()> {
     // Do this first for a better error message.
-    let packed_check = ensure_not_packed(&cx.orig, fields)?;
+    let packed_check = ensure_not_packed(&cx.orig, Some(fields))?;
 
     validate_struct(cx.orig.ident, fields)?;
 
@@ -402,9 +402,9 @@
     Ok(())
 }
 
-fn parse_enum(
-    cx: &mut Context<'_>,
-    DataEnum { brace_token, variants, .. }: &DataEnum,
+fn parse_enum<'a>(
+    cx: &mut Context<'a>,
+    DataEnum { brace_token, variants, .. }: &'a DataEnum,
     generate: &mut GenerateTokens,
 ) -> Result<()> {
     if let ProjReplace::Unnamed { span } = &cx.project_replace {
@@ -414,8 +414,12 @@
         ));
     }
 
-    // We don't need to check for `#[repr(packed)]`,
-    // since it does not apply to enums.
+    // #[repr(packed)] cannot be apply on enums and will be rejected by rustc.
+    // However, we should not rely on the behavior of rustc that rejects this.
+    // https://github.com/taiki-e/pin-project/pull/324#discussion_r612388001
+    //
+    // Do this first for a better error message.
+    ensure_not_packed(&cx.orig, None)?;
 
     validate_enum(*brace_token, variants)?;
 
@@ -483,7 +487,7 @@
     Ok(())
 }
 
-fn visit_variants(cx: &mut Context<'_>, variants: &Variants) -> Result<ProjectedVariants> {
+fn visit_variants<'a>(cx: &mut Context<'a>, variants: &'a Variants) -> Result<ProjectedVariants> {
     let mut proj_variants = TokenStream::new();
     let mut proj_ref_variants = TokenStream::new();
     let mut proj_own_variants = TokenStream::new();
@@ -540,10 +544,10 @@
     })
 }
 
-fn visit_fields(
-    cx: &mut Context<'_>,
+fn visit_fields<'a>(
+    cx: &mut Context<'a>,
     variant_ident: Option<&Ident>,
-    fields: &Fields,
+    fields: &'a Fields,
     delim: Delimiter,
 ) -> Result<ProjectedFields> {
     fn surround(delim: Delimiter, tokens: TokenStream) -> TokenStream {
@@ -561,8 +565,8 @@
     for (i, Field { attrs, vis, ident, colon_token, ty }) in fields.iter().enumerate() {
         let binding = ident.clone().unwrap_or_else(|| format_ident!("_{}", i));
         proj_pat.extend(quote!(#binding,));
+        let lifetime = &cx.proj.lifetime;
         if attrs.position_exact(PIN)?.is_some() {
-            let lifetime = &cx.proj.lifetime;
             proj_fields.extend(quote! {
                 #vis #ident #colon_token ::pin_project::__private::Pin<&#lifetime mut (#ty)>,
             });
@@ -579,10 +583,9 @@
                 #ident #colon_token ::pin_project::__private::PhantomData,
             });
 
-            cx.pinned_fields.push(ty.clone());
+            cx.pinned_fields.push(ty);
             pinned_bindings.push(binding);
         } else {
-            let lifetime = &cx.proj.lifetime;
             proj_fields.extend(quote! {
                 #vis #ident #colon_token &#lifetime mut (#ty),
             });
@@ -996,8 +999,8 @@
 /// This currently does two checks:
 /// * Checks the attributes of structs to ensure there is no `[repr(packed)]`.
 /// * Generates a function that borrows fields without an unsafe block and
-///   forbidding `safe_packed_borrows` lint.
-fn ensure_not_packed(orig: &OriginalType<'_>, fields: &Fields) -> Result<TokenStream> {
+///   forbidding `unaligned_references` lint.
+fn ensure_not_packed(orig: &OriginalType<'_>, fields: Option<&Fields>) -> Result<TokenStream> {
     for meta in orig.attrs.iter().filter_map(|attr| attr.parse_meta().ok()) {
         if let Meta::List(list) = meta {
             if list.path.is_ident("repr") {
@@ -1005,22 +1008,36 @@
                     match repr {
                         NestedMeta::Meta(Meta::Path(path))
                         | NestedMeta::Meta(Meta::List(MetaList { path, .. }))
-                            if path.is_ident("packed") =>
-                        {
-                            return Err(error!(
-                                repr,
-                                "#[pin_project] attribute may not be used on #[repr(packed)] types"
-                            ));
+                        | NestedMeta::Meta(Meta::NameValue(MetaNameValue { path, .. })) => {
+                            if path.is_ident("packed") {
+                                let msg = if fields.is_none() {
+                                    // #[repr(packed)] cannot be apply on enums and will be rejected by rustc.
+                                    // However, we should not rely on the behavior of rustc that rejects this.
+                                    // https://github.com/taiki-e/pin-project/pull/324#discussion_r612388001
+                                    "#[repr(packed)] attribute should be applied to a struct or union"
+                                } else if let NestedMeta::Meta(Meta::NameValue(..)) = repr {
+                                    // #[repr(packed = "")] is not valid format of #[repr(packed)] and will be
+                                    // rejected by rustc.
+                                    // However, we should not rely on the behavior of rustc that rejects this.
+                                    // https://github.com/taiki-e/pin-project/pull/324#discussion_r612388001
+                                    "#[repr(packed)] attribute should not be name-value pair"
+                                } else {
+                                    "#[pin_project] attribute may not be used on #[repr(packed)] types"
+                                };
+                                return Err(error!(repr, msg));
+                            }
                         }
-                        _ => {}
+                        NestedMeta::Lit(..) => {}
                     }
                 }
             }
         }
     }
 
-    // As proc-macro-derive can't rewrite the structure definition,
-    // it's probably no longer necessary, but it keeps it for now.
+    let fields = match fields {
+        Some(fields) => fields,
+        None => return Ok(TokenStream::new()),
+    };
 
     // Workaround for https://github.com/taiki-e/pin-project/issues/32
     // Through the tricky use of proc macros, it's possible to bypass
@@ -1029,7 +1046,7 @@
     // struct, we generate code like this:
     //
     // ```rust
-    // #[forbid(safe_packed_borrows)]
+    // #[forbid(unaligned_references)]
     // fn assert_not_repr_packed(val: &MyStruct) {
     //     let _field1 = &val.field1;
     //     let _field2 = &val.field2;
@@ -1038,10 +1055,8 @@
     // }
     // ```
     //
-    // Taking a reference to a packed field is unsafe, and applying
-    // `#[forbid(safe_packed_borrows)]` makes sure that doing this without
-    // an `unsafe` block (which we deliberately do not generate)
-    // is a hard error.
+    // Taking a reference to a packed field is UB, and applying
+    // `#[forbid(unaligned_references)]` makes sure that doing this is a hard error.
     //
     // If the struct ends up having `#[repr(packed)]` applied somehow,
     // this will generate an (unfriendly) error message. Under all reasonable
@@ -1061,6 +1076,21 @@
     // `#[repr(packed)]` in the first place.
     //
     // See also https://github.com/taiki-e/pin-project/pull/34.
+    //
+    // Note:
+    // - pin-project v0.4.3 or later (#135, v0.4.0-v0.4.2 are already yanked for
+    //   another reason) is internally proc-macro-derive, so they are not
+    //   affected by the problem that the struct definition is rewritten by
+    //   another macro after the #[pin_project] is expanded.
+    //   So this is probably no longer necessary, but it keeps it for now.
+    //
+    // - Lint-based tricks aren't perfect, but they're much better than nothing:
+    //   https://github.com/taiki-e/pin-project-lite/issues/26
+    //
+    // - Enable both unaligned_references and safe_packed_borrows lints
+    //   because unaligned_references lint does not exist in older compilers:
+    //   https://github.com/taiki-e/pin-project-lite/pull/55
+    //   https://github.com/rust-lang/rust/pull/82525
     let mut field_refs = vec![];
     match fields {
         Fields::Named(FieldsNamed { named, .. }) => {
@@ -1080,7 +1110,7 @@
     let (impl_generics, ty_generics, where_clause) = orig.generics.split_for_impl();
     let ident = orig.ident;
     Ok(quote! {
-        #[forbid(safe_packed_borrows)]
+        #[forbid(unaligned_references, safe_packed_borrows)]
         fn __assert_not_repr_packed #impl_generics (this: &#ident #ty_generics) #where_clause {
             #(let _ = #field_refs;)*
         }
diff --git a/src/pinned_drop.rs b/src/pinned_drop.rs
index ecf52dd..a28a701 100644
--- a/src/pinned_drop.rs
+++ b/src/pinned_drop.rs
@@ -189,6 +189,9 @@
         None
     }
 
+    // `PinnedDrop` is a private trait and should not appear in docs.
+    item.attrs.push(parse_quote!(#[doc(hidden)]));
+
     let path = &mut item.trait_.as_mut().unwrap().1;
     *path = parse_quote_spanned! { path.span() =>
         ::pin_project::__private::PinnedDrop
diff --git a/src/utils.rs b/src/utils.rs
index 37f35ba..2db00e2 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -176,7 +176,9 @@
 // visitors
 
 // Replace `self`/`Self` with `__self`/`self_ty`.
-// Based on https://github.com/dtolnay/async-trait/blob/0.1.35/src/receiver.rs
+// Based on:
+// - https://github.com/dtolnay/async-trait/blob/0.1.35/src/receiver.rs
+// - https://github.com/dtolnay/async-trait/commit/6029cbf375c562ca98fa5748e9d950a8ff93b0e7
 
 pub(crate) struct ReplaceReceiver<'a>(pub(crate) &'a TypePath);
 
@@ -313,7 +315,6 @@
     // `Self::method` -> `<Receiver>::method`
     fn visit_expr_path_mut(&mut self, expr: &mut ExprPath) {
         if expr.qself.is_none() {
-            prepend_underscore_to_self(&mut expr.path.segments[0].ident);
             self.self_to_qself(&mut expr.qself, &mut expr.path);
         }
         visit_mut::visit_expr_path_mut(self, expr);
@@ -341,6 +342,16 @@
         visit_mut::visit_pat_tuple_struct_mut(self, pat);
     }
 
+    fn visit_path_mut(&mut self, path: &mut Path) {
+        if path.segments.len() == 1 {
+            // Replace `self`, but not `self::function`.
+            prepend_underscore_to_self(&mut path.segments[0].ident);
+        }
+        for segment in &mut path.segments {
+            self.visit_path_arguments_mut(&mut segment.arguments);
+        }
+    }
+
     fn visit_item_mut(&mut self, item: &mut Item) {
         match item {
             // Visit `macro_rules!` because locally defined macros can refer to `self`.