diff options
author | Haibo Huang <hhb@google.com> | 2020-09-09 19:30:35 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-09-09 19:30:35 +0000 |
commit | 2e6872ec22c099b78e7e70dca9cba7068a683804 (patch) | |
tree | 3a2b6c1ac9b2f57c6ca3044feda8ec226ef4c6a2 | |
parent | a36d91cba1184e2ede9bfd0849fa46ecf88c4fa8 (diff) | |
parent | c5daa0e8e0fa00cc204ad2f2ef541cfc9fded015 (diff) | |
download | async-trait-2e6872ec22c099b78e7e70dca9cba7068a683804.tar.gz |
Merge "Upgrade rust/crates/async-trait to 0.1.40" am: 1a823a30b4 am: 6153cd63ba am: 4ec06917e3 am: c5daa0e8e0
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/async-trait/+/1417616
Change-Id: Ic45bfc9ba1783f5d231bea6daa6b3ecb2262e190
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | Cargo.toml.orig | 2 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | src/expand.rs | 7 | ||||
-rw-r--r-- | src/receiver.rs | 20 | ||||
-rw-r--r-- | tests/test.rs | 55 |
7 files changed, 82 insertions, 14 deletions
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" } } @@ -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" @@ -7,13 +7,13 @@ third_party { } 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 @@ fn transform_block( }; 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 @@ pub fn has_self_in_block(block: &mut Block) -> bool { 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 @@ impl VisitMut for HasSelf { 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 @@ impl VisitMut for ReplaceReceiver { } } - 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 @@ pub mod issue92 { } } +// 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 @@ mod issue104 { } // 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 @@ mod issue106 { } // 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 @@ mod issue110 { } // 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 @@ mod issue120 { 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 () {} +} |