Upgrade async-trait to 0.1.67 am: 58e0c00afa am: 5da30f30bb

Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/async-trait/+/2504755

Change-Id: I83fcfaa04fec50ad15e0c96faa845567f8f1f501
Signed-off-by: Automerger Merge Worker <[email protected]>
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 4b97a9e..85b96d9 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
 {
   "git": {
-    "sha1": "6a13fce88235ebd11c0c67f419a3153dcd349eb9"
+    "sha1": "f8a86505696c2206676cf2355dce1a6a27d28005"
   },
   "path_in_vcs": ""
 }
\ No newline at end of file
diff --git a/.clippy.toml b/.clippy.toml
index 21a08b0..0d369b5 100644
--- a/.clippy.toml
+++ b/.clippy.toml
@@ -1 +1 @@
-msrv = "1.39.0"
+msrv = "1.56.0"
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9443750..6ac696a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -3,6 +3,7 @@
 on:
   push:
   pull_request:
+  workflow_dispatch:
   schedule: [cron: "40 1 * * *"]
 
 permissions:
@@ -23,30 +24,20 @@
     strategy:
       fail-fast: false
       matrix:
-        rust: [beta, stable, 1.56.0]
-        include:
-          - rust: nightly
-            rustflags: --cfg async_trait_nightly_testing
+        rust: [nightly, beta, stable, 1.56.0]
     timeout-minutes: 45
     steps:
       - uses: actions/checkout@v3
       - uses: dtolnay/rust-toolchain@master
         with:
           toolchain: ${{matrix.rust}}
+      - name: Enable type layout randomization
+        run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV
+        if: matrix.rust == 'nightly'
+      - name: Enable nightly-only tests
+        run: echo RUSTFLAGS=${RUSTFLAGS}\ --cfg=async_trait_nightly_testing >> $GITHUB_ENV
+        if: matrix.rust == 'nightly'
       - run: cargo test
-        env:
-          RUSTFLAGS: ${{matrix.rustflags}} ${{env.RUSTFLAGS}}
-
-  msrv:
-    name: Rust 1.39.0
-    needs: pre_ci
-    if: needs.pre_ci.outputs.continue
-    runs-on: ubuntu-latest
-    timeout-minutes: 45
-    steps:
-      - uses: actions/checkout@v3
-      - uses: dtolnay/[email protected]
-      - run: cargo check
 
   clippy:
     name: Clippy
diff --git a/Android.bp b/Android.bp
index c7d70bb..0ded84e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -41,7 +41,7 @@
     name: "libasync_trait",
     crate_name: "async_trait",
     cargo_env_compat: true,
-    cargo_pkg_version: "0.1.64",
+    cargo_pkg_version: "0.1.67",
     srcs: ["src/lib.rs"],
     edition: "2018",
     rustlibs: [
diff --git a/Cargo.toml b/Cargo.toml
index 5a6efbe..0e91d4a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,9 +11,9 @@
 
 [package]
 edition = "2018"
-rust-version = "1.39"
+rust-version = "1.56"
 name = "async-trait"
-version = "0.1.64"
+version = "0.1.67"
 authors = ["David Tolnay <[email protected]>"]
 description = "Type erasure for async trait methods"
 documentation = "https://docs.rs/async-trait"
@@ -39,7 +39,7 @@
 version = "1.0"
 
 [dependencies.syn]
-version = "1.0.96"
+version = "2.0"
 features = [
     "full",
     "visit-mut",
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 2dd4171..d99bf18 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
 [package]
 name = "async-trait"
-version = "0.1.64"
+version = "0.1.67"
 authors = ["David Tolnay <[email protected]>"]
 categories = ["asynchronous", "no-std"]
 description = "Type erasure for async trait methods"
@@ -9,7 +9,7 @@
 keywords = ["async"]
 license = "MIT OR Apache-2.0"
 repository = "https://github.com/dtolnay/async-trait"
-rust-version = "1.39"
+rust-version = "1.56"
 
 [lib]
 proc-macro = true
@@ -17,7 +17,7 @@
 [dependencies]
 proc-macro2 = "1.0"
 quote = "1.0"
-syn = { version = "1.0.96", features = ["full", "visit-mut"] }
+syn = { version = "2.0", features = ["full", "visit-mut"] }
 
 [dev-dependencies]
 futures = "0.3"
diff --git a/METADATA b/METADATA
index 0445905..e6e568a 100644
--- a/METADATA
+++ b/METADATA
@@ -11,13 +11,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/async-trait/async-trait-0.1.64.crate"
+    value: "https://static.crates.io/crates/async-trait/async-trait-0.1.67.crate"
   }
-  version: "0.1.64"
+  version: "0.1.67"
   license_type: NOTICE
   last_upgrade_date {
     year: 2023
-    month: 2
-    day: 1
+    month: 3
+    day: 23
   }
 }
diff --git a/src/expand.rs b/src/expand.rs
index 88338db..362ba78 100644
--- a/src/expand.rs
+++ b/src/expand.rs
@@ -10,7 +10,7 @@
 use syn::visit_mut::{self, VisitMut};
 use syn::{
     parse_quote, parse_quote_spanned, Attribute, Block, FnArg, GenericArgument, GenericParam,
-    Generics, Ident, ImplItem, Lifetime, LifetimeDef, Pat, PatIdent, PathArguments, Receiver,
+    Generics, Ident, ImplItem, Lifetime, LifetimeParam, Pat, PatIdent, PathArguments, Receiver,
     ReturnType, Signature, Stmt, Token, TraitItem, Type, TypePath, WhereClause,
 };
 
@@ -36,7 +36,7 @@
 }
 
 impl Context<'_> {
-    fn lifetimes<'a>(&'a self, used: &'a [Lifetime]) -> impl Iterator<Item = &'a LifetimeDef> {
+    fn lifetimes<'a>(&'a self, used: &'a [Lifetime]) -> impl Iterator<Item = &'a LifetimeParam> {
         let generics = match self {
             Context::Trait { generics, .. } => generics,
             Context::Impl { impl_generics, .. } => impl_generics,
@@ -60,7 +60,7 @@
                 supertraits: &input.supertraits,
             };
             for inner in &mut input.items {
-                if let TraitItem::Method(method) = inner {
+                if let TraitItem::Fn(method) = inner {
                     let sig = &mut method.sig;
                     if sig.asyncness.is_some() {
                         let block = &mut method.default;
@@ -80,13 +80,6 @@
             }
         }
         Item::Impl(input) => {
-            let mut lifetimes = CollectLifetimes::new("'impl");
-            lifetimes.visit_type_mut(&mut *input.self_ty);
-            lifetimes.visit_path_mut(&mut input.trait_.as_mut().unwrap().1);
-            let params = &input.generics.params;
-            let elided = lifetimes.elided;
-            input.generics.params = parse_quote!(#(#elided,)* #params);
-
             let mut associated_type_impl_traits = Set::new();
             for inner in &input.items {
                 if let ImplItem::Type(assoc) = inner {
@@ -101,7 +94,7 @@
                 associated_type_impl_traits: &associated_type_impl_traits,
             };
             for inner in &mut input.items {
-                if let ImplItem::Method(method) = inner {
+                if let ImplItem::Fn(method) = inner {
                     let sig = &mut method.sig;
                     if sig.asyncness.is_some() {
                         let block = &mut method.block;
@@ -167,7 +160,7 @@
         ReturnType::Type(arrow, ret) => (*arrow, quote!(#ret)),
     };
 
-    let mut lifetimes = CollectLifetimes::new("'life");
+    let mut lifetimes = CollectLifetimes::new();
     for arg in sig.inputs.iter_mut() {
         match arg {
             FnArg::Receiver(arg) => lifetimes.visit_receiver_mut(arg),
@@ -215,7 +208,7 @@
         sig.generics.lt_token = Some(Token![<](sig.ident.span()));
     }
     if sig.generics.gt_token.is_none() {
-        sig.generics.gt_token = Some(Token![>](sig.paren_token.span));
+        sig.generics.gt_token = Some(Token![>](sig.paren_token.span.join()));
     }
 
     for elided in lifetimes.elided {
@@ -230,46 +223,35 @@
         .push(parse_quote_spanned!(default_span=> 'async_trait));
 
     if has_self {
-        let bounds: &[InferredBound] = match sig.inputs.iter().next() {
-            Some(FnArg::Receiver(Receiver {
-                reference: Some(_),
-                mutability: None,
-                ..
-            })) => &[InferredBound::Sync],
-            Some(FnArg::Typed(arg))
-                if match arg.pat.as_ref() {
-                    Pat::Ident(pat) => pat.ident == "self",
-                    _ => false,
-                } =>
-            {
-                match arg.ty.as_ref() {
-                    // self: &Self
-                    Type::Reference(ty) if ty.mutability.is_none() => &[InferredBound::Sync],
-                    // self: Arc<Self>
-                    Type::Path(ty)
-                        if {
-                            let segment = ty.path.segments.last().unwrap();
-                            segment.ident == "Arc"
-                                && match &segment.arguments {
-                                    PathArguments::AngleBracketed(arguments) => {
-                                        arguments.args.len() == 1
-                                            && match &arguments.args[0] {
-                                                GenericArgument::Type(Type::Path(arg)) => {
-                                                    arg.path.is_ident("Self")
-                                                }
-                                                _ => false,
+        let bounds: &[InferredBound] = if let Some(receiver) = sig.receiver() {
+            match receiver.ty.as_ref() {
+                // self: &Self
+                Type::Reference(ty) if ty.mutability.is_none() => &[InferredBound::Sync],
+                // self: Arc<Self>
+                Type::Path(ty)
+                    if {
+                        let segment = ty.path.segments.last().unwrap();
+                        segment.ident == "Arc"
+                            && match &segment.arguments {
+                                PathArguments::AngleBracketed(arguments) => {
+                                    arguments.args.len() == 1
+                                        && match &arguments.args[0] {
+                                            GenericArgument::Type(Type::Path(arg)) => {
+                                                arg.path.is_ident("Self")
                                             }
-                                    }
-                                    _ => false,
+                                            _ => false,
+                                        }
                                 }
-                        } =>
-                    {
-                        &[InferredBound::Sync, InferredBound::Send]
-                    }
-                    _ => &[InferredBound::Send],
+                                _ => false,
+                            }
+                    } =>
+                {
+                    &[InferredBound::Sync, InferredBound::Send]
                 }
+                _ => &[InferredBound::Send],
             }
-            _ => &[InferredBound::Send],
+        } else {
+            &[InferredBound::Send]
         };
 
         let bounds = bounds.iter().filter_map(|bound| {
@@ -293,24 +275,24 @@
 
     for (i, arg) in sig.inputs.iter_mut().enumerate() {
         match arg {
-            FnArg::Receiver(Receiver {
-                reference: Some(_), ..
-            }) => {}
-            FnArg::Receiver(arg) => arg.mutability = None,
+            FnArg::Receiver(receiver) => {
+                if receiver.reference.is_none() {
+                    receiver.mutability = None;
+                }
+            }
             FnArg::Typed(arg) => {
-                let type_is_reference = match *arg.ty {
-                    Type::Reference(_) => true,
-                    _ => false,
-                };
-                if let Pat::Ident(pat) = &mut *arg.pat {
-                    if pat.ident == "self" || !type_is_reference {
+                if match *arg.ty {
+                    Type::Reference(_) => false,
+                    _ => true,
+                } {
+                    if let Pat::Ident(pat) = &mut *arg.pat {
                         pat.by_ref = None;
                         pat.mutability = None;
+                    } else {
+                        let positional = positional_arg(i, &arg.pat);
+                        let m = mut_pat(&mut arg.pat);
+                        arg.pat = parse_quote!(#m #positional);
                     }
-                } else if !type_is_reference {
-                    let positional = positional_arg(i, &arg.pat);
-                    let m = mut_pat(&mut arg.pat);
-                    arg.pat = parse_quote!(#m #positional);
                 }
                 AddLifetimeToImplTrait.visit_type_mut(&mut arg.ty);
             }
@@ -373,26 +355,18 @@
                 // the parameter, forward it to the variable.
                 //
                 // This is currently not applied to the `self` parameter.
-                let attrs = arg.attrs.iter().filter(|attr| attr.path.is_ident("cfg"));
+                let attrs = arg.attrs.iter().filter(|attr| attr.path().is_ident("cfg"));
 
-                if let Pat::Ident(PatIdent {
+                if let Type::Reference(_) = *arg.ty {
+                    quote!()
+                } else if let Pat::Ident(PatIdent {
                     ident, mutability, ..
                 }) = &*arg.pat
                 {
-                    if ident == "self" {
-                        self_span = Some(ident.span());
-                        let prefixed = Ident::new("__self", ident.span());
-                        quote!(let #mutability #prefixed = #ident;)
-                    } else if let Type::Reference(_) = *arg.ty {
-                        quote!()
-                    } else {
-                        quote! {
-                            #(#attrs)*
-                            let #mutability #ident = #ident;
-                        }
+                    quote! {
+                        #(#attrs)*
+                        let #mutability #ident = #ident;
                     }
-                } else if let Type::Reference(_) = *arg.ty {
-                    quote!()
                 } else {
                     let pat = &arg.pat;
                     let ident = positional_arg(i, pat);
diff --git a/src/lib.rs b/src/lib.rs
index 8ca5032..ec893f6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -303,12 +303,14 @@
 //! let object = &value as &dyn ObjectSafe;
 //! ```
 
+#![doc(html_root_url = "https://docs.rs/async-trait/0.1.67")]
 #![allow(
     clippy::default_trait_access,
     clippy::doc_markdown,
     clippy::explicit_auto_deref,
     clippy::if_not_else,
     clippy::items_after_statements,
+    clippy::match_like_matches_macro,
     clippy::module_name_repetitions,
     clippy::shadow_unrelated,
     clippy::similar_names,
diff --git a/src/lifetime.rs b/src/lifetime.rs
index 86eac24..a7babfb 100644
--- a/src/lifetime.rs
+++ b/src/lifetime.rs
@@ -9,15 +9,13 @@
 pub struct CollectLifetimes {
     pub elided: Vec<Lifetime>,
     pub explicit: Vec<Lifetime>,
-    pub name: &'static str,
 }
 
 impl CollectLifetimes {
-    pub fn new(name: &'static str) -> Self {
+    pub fn new() -> Self {
         CollectLifetimes {
             elided: Vec::new(),
             explicit: Vec::new(),
-            name,
         }
     }
 
@@ -37,7 +35,7 @@
     }
 
     fn next_lifetime(&mut self, span: Span) -> Lifetime {
-        let name = format!("{}{}", self.name, self.elided.len());
+        let name = format!("'life{}", self.elided.len());
         let life = Lifetime::new(&name, span);
         self.elided.push(life.clone());
         life
@@ -48,6 +46,8 @@
     fn visit_receiver_mut(&mut self, arg: &mut Receiver) {
         if let Some((reference, lifetime)) = &mut arg.reference {
             self.visit_opt_lifetime(*reference, lifetime);
+        } else {
+            visit_mut::visit_type_mut(self, &mut arg.ty);
         }
     }
 
diff --git a/src/receiver.rs b/src/receiver.rs
index 2230db6..6de5090 100644
--- a/src/receiver.rs
+++ b/src/receiver.rs
@@ -2,8 +2,7 @@
 use std::iter::FromIterator;
 use syn::visit_mut::{self, VisitMut};
 use syn::{
-    Block, ExprPath, Ident, Item, Macro, Pat, PatIdent, PatPath, Path, Receiver, Signature, Token,
-    TypePath,
+    Block, ExprPath, Ident, Item, Macro, Pat, PatIdent, Path, Receiver, Signature, Token, TypePath,
 };
 
 pub fn has_self_in_sig(sig: &mut Signature) -> bool {
@@ -60,11 +59,6 @@
         visit_mut::visit_expr_path_mut(self, expr);
     }
 
-    fn visit_pat_path_mut(&mut self, pat: &mut PatPath) {
-        self.0 |= pat.path.segments[0].ident == "Self";
-        visit_mut::visit_pat_path_mut(self, pat);
-    }
-
     fn visit_type_path_mut(&mut self, ty: &mut TypePath) {
         self.0 |= ty.path.segments[0].ident == "Self";
         visit_mut::visit_type_path_mut(self, ty);
diff --git a/tests/test.rs b/tests/test.rs
index 458904e..f36618f 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -4,6 +4,7 @@
 )]
 #![deny(rust_2021_compatibility)]
 #![allow(
+    clippy::let_underscore_untyped,
     clippy::let_unit_value,
     clippy::missing_panics_doc,
     clippy::missing_safety_doc,
@@ -740,7 +741,6 @@
 
 // https://github.com/dtolnay/async-trait/issues/68
 pub mod issue68 {
-    #[rustversion::since(1.40)] // procedural macros cannot expand to macro definitions in 1.39.
     #[async_trait::async_trait]
     pub trait Example {
         async fn method(&self) {
@@ -1584,3 +1584,22 @@
         }
     }
 }
+
+// https://github.com/dtolnay/async-trait/issues/238
+pub mod issue238 {
+    #![deny(single_use_lifetimes)]
+
+    use async_trait::async_trait;
+
+    #[async_trait]
+    pub trait Trait {
+        async fn f();
+    }
+
+    pub struct Struct;
+
+    #[async_trait]
+    impl Trait for &Struct {
+        async fn f() {}
+    }
+}
diff --git a/tests/ui/lifetime-span.stderr b/tests/ui/lifetime-span.stderr
index 999da04..fa16ac7 100644
--- a/tests/ui/lifetime-span.stderr
+++ b/tests/ui/lifetime-span.stderr
@@ -4,13 +4,12 @@
 12 | impl Trait for A {
    |      ^^^^^ expected lifetime parameter
    |
-   = note: assuming a `'static` lifetime...
 help: indicate the anonymous lifetime
    |
 12 | impl Trait<'_> for A {
    |           ++++
 
-error[E0107]: this trait takes 0 lifetime arguments but 1 lifetime argument was supplied
+error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied
   --> tests/ui/lifetime-span.rs:32:10
    |
 32 | impl<'r> Trait2<'r> for B {
diff --git a/tests/ui/must-use.stderr b/tests/ui/must-use.stderr
index fd6fc31..9b71d10 100644
--- a/tests/ui/must-use.stderr
+++ b/tests/ui/must-use.stderr
@@ -9,3 +9,7 @@
    |
 1  | #![deny(unused_must_use)]
    |         ^^^^^^^^^^^^^^^
+help: use `let _ = ...` to ignore the resulting value
+   |
+18 |     let _ = Thing.f();
+   |     +++++++
diff --git a/tests/ui/self-span.stderr b/tests/ui/self-span.stderr
index 8743e57..04493f8 100644
--- a/tests/ui/self-span.stderr
+++ b/tests/ui/self-span.stderr
@@ -2,7 +2,7 @@
   --> tests/ui/self-span.rs:17:21
    |
 17 |         let _: () = self;
-   |                --   ^^^^ expected `()`, found struct `S`
+   |                --   ^^^^ expected `()`, found `S`
    |                |
    |                expected due to this
 
@@ -16,7 +16,7 @@
   --> tests/ui/self-span.rs:25:21
    |
 25 |         let _: () = self;
-   |                --   ^^^^ expected `()`, found enum `E`
+   |                --   ^^^^ expected `()`, found `E`
    |                |
    |                expected due to this