aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2020-09-01 20:28:34 -0700
committerHaibo Huang <hhb@google.com>2020-09-01 20:28:34 -0700
commit62e9b29684f8632534ed342a10b9227e3a255d89 (patch)
tree3a2b6c1ac9b2f57c6ca3044feda8ec226ef4c6a2
parent31a1c05149b3410cf01250284575f54e55668e29 (diff)
downloadasync-trait-62e9b29684f8632534ed342a10b9227e3a255d89.tar.gz
Upgrade rust/crates/async-trait to 0.1.40
Test: make Change-Id: Ifae614e646fac929455de2cb4639578ae954a7f9
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig2
-rw-r--r--METADATA8
-rw-r--r--src/expand.rs7
-rw-r--r--src/receiver.rs20
-rw-r--r--tests/test.rs55
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"
}
}
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 @@ 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 () {}
+}