Merge "Upgrade rust/crates/async-trait to 0.1.40" am: 1a823a30b4

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

Change-Id: I058764e81842db03084149b9ead9705671de631e
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 46160ea..65f73e6 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
 {
   "git": {
-    "sha1": "7e82be9fd3c72dd64d910ca8f88733607e52d690"
+    "sha1": "6695236fd9addd26caa11e2867ccf2adc9ffce81"
   }
 }
diff --git a/Cargo.toml b/Cargo.toml
index d4be2ff..968245f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
 [package]
 edition = "2018"
 name = "async-trait"
-version = "0.1.38"
+version = "0.1.40"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
 description = "Type erasure for async trait methods"
 documentation = "https://docs.rs/async-trait"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 41eb5c7..788bcdf 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
 [package]
 name = "async-trait"
-version = "0.1.38"
+version = "0.1.40"
 authors = ["David Tolnay <dtolnay@gmail.com>"]
 edition = "2018"
 license = "MIT OR Apache-2.0"
diff --git a/METADATA b/METADATA
index 4bc9e4e..059a608 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/async-trait/async-trait-0.1.38.crate"
+    value: "https://static.crates.io/crates/async-trait/async-trait-0.1.40.crate"
   }
-  version: "0.1.38"
+  version: "0.1.40"
   license_type: NOTICE
   last_upgrade_date {
     year: 2020
-    month: 8
-    day: 17
+    month: 9
+    day: 1
   }
 }
diff --git a/src/expand.rs b/src/expand.rs
index 7c3ab5a..f868c7d 100644
--- a/src/expand.rs
+++ b/src/expand.rs
@@ -284,6 +284,13 @@
     };
 
     let mut outer_generics = generics.clone();
+    for p in &mut outer_generics.params {
+        match p {
+            GenericParam::Type(t) => t.default = None,
+            GenericParam::Const(c) => c.default = None,
+            GenericParam::Lifetime(_) => {}
+        }
+    }
     if !has_self {
         if let Some(mut where_clause) = outer_generics.where_clause {
             where_clause.predicates = where_clause
diff --git a/src/receiver.rs b/src/receiver.rs
index 1e9e397..4273359 100644
--- a/src/receiver.rs
+++ b/src/receiver.rs
@@ -29,6 +29,14 @@
     visitor.0
 }
 
+fn has_self_in_token_stream(tokens: TokenStream) -> bool {
+    tokens.into_iter().any(|tt| match tt {
+        TokenTree::Ident(ident) => ident == "Self",
+        TokenTree::Group(group) => has_self_in_token_stream(group.stream()),
+        _ => false,
+    })
+}
+
 struct HasSelf(bool);
 
 impl VisitMut for HasSelf {
@@ -54,6 +62,12 @@
     fn visit_item_mut(&mut self, _: &mut Item) {
         // Do not recurse into nested items.
     }
+
+    fn visit_macro_mut(&mut self, mac: &mut Macro) {
+        if !contains_fn(mac.tokens.clone()) {
+            self.0 |= has_self_in_token_stream(mac.tokens.clone());
+        }
+    }
 }
 
 pub struct ReplaceReceiver {
@@ -278,14 +292,14 @@
         }
     }
 
-    fn visit_macro_mut(&mut self, i: &mut Macro) {
+    fn visit_macro_mut(&mut self, mac: &mut Macro) {
         // We can't tell in general whether `self` inside a macro invocation
         // refers to the self in the argument list or a different self
         // introduced within the macro. Heuristic: if the macro input contains
         // `fn`, then `self` is more likely to refer to something other than the
         // outer function's self argument.
-        if !contains_fn(i.tokens.clone()) {
-            self.visit_token_stream(&mut i.tokens);
+        if !contains_fn(mac.tokens.clone()) {
+            self.visit_token_stream(&mut mac.tokens);
         }
     }
 }
diff --git a/tests/test.rs b/tests/test.rs
index 4ecab07..2d8b75b 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -883,8 +883,37 @@
     }
 }
 
+// https://github.com/dtolnay/async-trait/issues/92#issuecomment-683370136
+pub mod issue92_2 {
+    use async_trait::async_trait;
+
+    macro_rules! mac {
+        ($($tt:tt)*) => {
+            $($tt)*
+        };
+    }
+
+    pub trait Trait1 {
+        fn func1();
+    }
+
+    #[async_trait]
+    pub trait Trait2: Trait1 {
+        async fn func2() {
+            mac!(Self::func1());
+
+            macro_rules! mac2 {
+                ($($tt:tt)*) => {
+                    Self::func1();
+                };
+            }
+            mac2!();
+        }
+    }
+}
+
 // https://github.com/dtolnay/async-trait/issues/104
-mod issue104 {
+pub mod issue104 {
     use async_trait::async_trait;
 
     #[async_trait]
@@ -909,7 +938,7 @@
 }
 
 // https://github.com/dtolnay/async-trait/issues/106
-mod issue106 {
+pub mod issue106 {
     use async_trait::async_trait;
     use std::future::Future;
 
@@ -941,7 +970,7 @@
 }
 
 // https://github.com/dtolnay/async-trait/issues/110
-mod issue110 {
+pub mod issue110 {
     #![deny(clippy::all)]
 
     use async_trait::async_trait;
@@ -963,7 +992,7 @@
 }
 
 // https://github.com/dtolnay/async-trait/issues/120
-mod issue120 {
+pub mod issue120 {
     #![deny(clippy::trivially_copy_pass_by_ref)]
 
     use async_trait::async_trait;
@@ -978,3 +1007,21 @@
         async fn f(&self) {}
     }
 }
+
+// https://github.com/dtolnay/async-trait/issues/123
+pub mod issue123 {
+    use async_trait::async_trait;
+
+    #[async_trait]
+    trait Trait<T = ()> {
+        async fn f(&self) -> &str
+        where
+            T: 'async_trait,
+        {
+            "default"
+        }
+    }
+
+    #[async_trait]
+    impl<T> Trait<T> for () {}
+}