[rust_crates] Update async-trait to 0.1.36
Fixed: 55699
Change-Id: I1f8cc57c0ae065de2ae75d3474428b5225d7556a
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/404925
Reviewed-by: Tyler Mandry <tmandry@google.com>
Reviewed-by: Paul Faria <paulfaria@google.com>
Testability-Review: Bryce Lee <brycelee@google.com>
Commit-Queue: Bryce Lee <brycelee@google.com>
diff --git a/third_party/rust_crates/BUILD.gn b/third_party/rust_crates/BUILD.gn
index a2e0494..cf83b0a 100644
--- a/third_party/rust_crates/BUILD.gn
+++ b/third_party/rust_crates/BUILD.gn
@@ -22,7 +22,7 @@
}
}
group("async-trait") {
- deps = [ ":async-trait-v0_1_22($host_toolchain)" ]
+ deps = [ ":async-trait-v0_1_36($host_toolchain)" ]
}
group("base64") {
@@ -1108,10 +1108,10 @@
]
}
-rust_proc_macro("async-trait-v0_1_22") {
+rust_proc_macro("async-trait-v0_1_36") {
crate_name = "async_trait"
crate_root = "//third_party/rust_crates/vendor/async-trait/src/lib.rs"
- output_name = "async_trait-815e9516aea025f1"
+ output_name = "async_trait-ea6c1c1ca784b963"
configs -= [
"//build/config:rust_edition_2018",
"//build/config:rust_2018_idioms",
@@ -1127,8 +1127,8 @@
rustflags = [
"--cap-lints=allow",
"--edition=2018",
- "-Cmetadata=815e9516aea025f1",
- "-Cextra-filename=-815e9516aea025f1",
+ "-Cmetadata=ea6c1c1ca784b963",
+ "-Cextra-filename=-ea6c1c1ca784b963",
]
}
@@ -8350,7 +8350,7 @@
]
deps = []
- deps += [ ":async-trait-v0_1_22($host_toolchain)" ]
+ deps += [ ":async-trait-v0_1_36($host_toolchain)" ]
deps += [ ":backtrace-v0_3_42" ]
deps += [ ":enum-as-inner-v0_3_0($host_toolchain)" ]
deps += [ ":futures-v0_3_5" ]
diff --git a/third_party/rust_crates/Cargo.lock b/third_party/rust_crates/Cargo.lock
index fad64077..18468cb 100644
--- a/third_party/rust_crates/Cargo.lock
+++ b/third_party/rust_crates/Cargo.lock
@@ -131,7 +131,7 @@
[[package]]
name = "async-trait"
-version = "0.1.22"
+version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -671,7 +671,7 @@
"arbitrary 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"argh 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"async-std 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "async-trait 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
+ "async-trait 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bitfield 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2902,7 +2902,7 @@
version = "0.19.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "async-trait 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
+ "async-trait 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
"backtrace 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)",
"enum-as-inner 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3307,7 +3307,7 @@
"checksum async-attributes 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "efd3d156917d94862e779f356c5acae312b08fd3121e792c857d7928c8088423"
"checksum async-std 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a45cee2749d880d7066e328a7e161c7470ced883b2fd000ca4643e9f1dd5083a"
"checksum async-task 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c17772156ef2829aadc587461c7753af20b7e8db1529bc66855add962a3b35d3"
-"checksum async-trait 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "c8df72488e87761e772f14ae0c2480396810e51b2c2ade912f97f0f7e5b95e3c"
+"checksum async-trait 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a265e3abeffdce30b2e26b7a11b222fe37c6067404001b434101457d0385eb92"
"checksum atom 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3c86699c3f02778ec07158376991c8f783dd1f2f95c579ffaf0738dc984b2fe2"
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
diff --git a/third_party/rust_crates/Cargo.toml b/third_party/rust_crates/Cargo.toml
index 864eb89..4930066 100644
--- a/third_party/rust_crates/Cargo.toml
+++ b/third_party/rust_crates/Cargo.toml
@@ -26,7 +26,7 @@
anyhow = "1.0.25"
arbitrary = { version = "0.4.0", features = ["derive"] }
argh = "0.1"
-async-trait = "0.1.11"
+async-trait = "0.1.36"
base64 = "0.9"
bincode = "1"
bitfield = "0.13"
diff --git a/third_party/rust_crates/vendor/async-trait/.cargo-checksum.json b/third_party/rust_crates/vendor/async-trait/.cargo-checksum.json
index 16f2fa5..1bf13cb 100644
--- a/third_party/rust_crates/vendor/async-trait/.cargo-checksum.json
+++ b/third_party/rust_crates/vendor/async-trait/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"895561e50ac299f8d10f624d587411ff22c6ecc393d0b82b2788cc0312349be5","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"f3bff9f787cb295496915cd37aaf3f80e08edebdd9604cbd6bcdaa8028e28d33","src/args.rs":"6eed5497db91752b3aae597943c39e769f60406b37055304e69e4699f1f87b15","src/expand.rs":"32000834ae9f6b34cc7d77e0c422332f65256863cc4fee348ce9e80d9df3588e","src/lib.rs":"23614cbb72bc3854038a4bd0572dfb80ff31c7707edc1525ecc2b5a08b8e428d","src/lifetime.rs":"25e559c34ff468c46f5587b70f7d62952b2a3d27594403a06e979d8dcc305b02","src/parse.rs":"2d99893d58a50391c9ae470bf924f23fa284f5eb99482119e3bcc4e781a82cf8","src/receiver.rs":"82974aa1eccb3c353eeb3d1ab405d5454fb6ce6ca060256949cc9c42754a3e9e","tests/compiletest.rs":"0a52a44786aea1c299c695bf948b2ed2081e4cc344e5c2cadceab4eb03d0010d","tests/executor/mod.rs":"620975b33cc2a494efb6bce230cf285a462b85e5fe12d71561b5bacd9d507b28","tests/test.rs":"12dacb2d21064f3273437eb29ca6eee93c9127c74986eb5647cb707c8c07de2f","tests/ui/send-not-implemented.rs":"5f1dd26f4eb34c653048e9658fbf6b41e2930d6222869b397ca4d8d7113a2809","tests/ui/send-not-implemented.stderr":"01f7df5b0efb3fa890cc4e26be520fb3fe59bb9ea9be349c7b971b6cde9d2308","tests/ui/unsupported-self.rs":"f7855bc39dab1fd2f533fb2e873a27c3757dcb9fb57001e4b19f58d3dda36d01","tests/ui/unsupported-self.stderr":"2b30517b790c666ea85442afc1c701ddc235d091372e175009aa084bd57b7070"},"package":"c8df72488e87761e772f14ae0c2480396810e51b2c2ade912f97f0f7e5b95e3c"}
\ No newline at end of file
+{"files":{"Cargo.toml":"5291df3bfbd7f13019595338d74a5c87b31627d97a79cb9f3f4f059a15e2d10d","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"1d97889a5b4b981a025a8d6fb3e080bac1885c84f7d1df7982ca90dac3a72ac6","src/args.rs":"6eed5497db91752b3aae597943c39e769f60406b37055304e69e4699f1f87b15","src/expand.rs":"8b51a5be668999ef1e30c72c8c0de2b02aebbaab1a2c13819d6b90e11a07ed03","src/lib.rs":"9b7e6f6c512b8f083641c0fb6c298249008b19ae9737186ee699e5007dbee628","src/lifetime.rs":"e51bd32dba9caf32ea241d2f4fbd83c29b5c71d0308d9c18268b9e4594ec9c76","src/parse.rs":"cd9032fe2c6dcf41050b3a59b9fb98eb9700a29bbe2fa011ee2854014c1666b7","src/receiver.rs":"8f71b8eb957506287e62fa11cc7710a5aefc6b6338a9923c4b3017f5a661aafb","src/respan.rs":"eef5b4467f58e1df4650a2331495c5e28eff8d54a3250506fc2f6c2da3366ada","tests/compiletest.rs":"0a52a44786aea1c299c695bf948b2ed2081e4cc344e5c2cadceab4eb03d0010d","tests/executor/mod.rs":"620975b33cc2a494efb6bce230cf285a462b85e5fe12d71561b5bacd9d507b28","tests/test.rs":"3c429103bf0a7c12ef554b9d1af4094410a359fc1bdf7addc67ed47fcd8948a5","tests/ui/bare-trait-object.rs":"4546e8bd6682de11920fa4c768295fed61954484ef0550dfadbc5677b77f29a5","tests/ui/bare-trait-object.stderr":"b63287594e6e5183e9b5b0e701fc4dd3a9b4fb0ea93eb910be56166e5fa4cdbd","tests/ui/delimiter-span.rs":"5e11150b1448f4c5b88a08aa579a663606ccaaed7f302e9465b42fc3489f0f3e","tests/ui/delimiter-span.stderr":"a1d7ead68b8d01e6e51c0943ccd683fb5fb8c3eae2d56feb22b0ef777949b87d","tests/ui/missing-body.rs":"d06c0da8c6044e7c790b924136f167e2edc0d0d3fa01f23521f3f08ca605929b","tests/ui/missing-body.stderr":"636a03cc42933b59d73032ce6cea862e33c16efb9c7fe7f27749247998bc9f23","tests/ui/must-use.rs":"75090c7df984df0996464337f60371d198bd0caf3f9f44b10d1e131f15fd4fca","tests/ui/must-use.stderr":"e6cb190e02f0226df6444065aaca3051f7db8ae599bba18a685155c52bb799b6","tests/ui/self-span.rs":"67ddde05907d7014bfb3f2c63d427b1d72d6c4369a9108a4335dac6bee5832b2","tests/ui/self-span.stderr":"6d0ce227490fa5a819b068d6e3e1a0b0160bc30c658d69c16ff7d5c8b0ef68ed","tests/ui/send-not-implemented.rs":"5f1dd26f4eb34c653048e9658fbf6b41e2930d6222869b397ca4d8d7113a2809","tests/ui/send-not-implemented.stderr":"17abb4f3593846fa05cb32c57e411ce471255badd3fa5a71eac4e99f0c0e571f","tests/ui/unsupported-self.rs":"f7855bc39dab1fd2f533fb2e873a27c3757dcb9fb57001e4b19f58d3dda36d01","tests/ui/unsupported-self.stderr":"2b30517b790c666ea85442afc1c701ddc235d091372e175009aa084bd57b7070"},"package":"a265e3abeffdce30b2e26b7a11b222fe37c6067404001b434101457d0385eb92"}
\ No newline at end of file
diff --git a/third_party/rust_crates/vendor/async-trait/Cargo.toml b/third_party/rust_crates/vendor/async-trait/Cargo.toml
index 128db64..675035a 100644
--- a/third_party/rust_crates/vendor/async-trait/Cargo.toml
+++ b/third_party/rust_crates/vendor/async-trait/Cargo.toml
@@ -13,13 +13,15 @@
[package]
edition = "2018"
name = "async-trait"
-version = "0.1.22"
+version = "0.1.36"
authors = ["David Tolnay <dtolnay@gmail.com>"]
description = "Type erasure for async trait methods"
documentation = "https://docs.rs/async-trait"
readme = "README.md"
license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/async-trait"
+[package.metadata.docs.rs]
+targets = ["x86_64-unknown-linux-gnu"]
[lib]
proc-macro = true
@@ -35,11 +37,15 @@
[dev-dependencies.rustversion]
version = "1.0"
+[dev-dependencies.tracing]
+version = "0.1.14"
+
+[dev-dependencies.tracing-attributes]
+version = "0.1.8"
+
+[dev-dependencies.tracing-futures]
+version = "0.2"
+
[dev-dependencies.trybuild]
version = "1.0.19"
features = ["diff"]
-
-[features]
-support_old_nightly = []
-[badges.travis-ci]
-repository = "dtolnay/async-trait"
diff --git a/third_party/rust_crates/vendor/async-trait/README.md b/third_party/rust_crates/vendor/async-trait/README.md
index 026e24a..7d3e050 100644
--- a/third_party/rust_crates/vendor/async-trait/README.md
+++ b/third_party/rust_crates/vendor/async-trait/README.md
@@ -1,16 +1,14 @@
Async trait methods
===================
-[![Build Status](https://api.travis-ci.com/dtolnay/async-trait.svg?branch=master)](https://travis-ci.com/dtolnay/async-trait)
-[![Latest Version](https://img.shields.io/crates/v/async-trait.svg)](https://crates.io/crates/async-trait)
-[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/async-trait)
+[<img alt="github" src="https://img.shields.io/badge/github-dtolnay/async--trait-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/async-trait)
+[<img alt="crates.io" src="https://img.shields.io/crates/v/async-trait.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/async-trait)
+[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-async--trait-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K" height="20">](https://docs.rs/async-trait)
+[<img alt="build status" src="https://img.shields.io/github/workflow/status/dtolnay/async-trait/CI/master?style=for-the-badge" height="20">](https://github.com/dtolnay/async-trait/actions?query=branch%3Amaster)
-The async/await language feature is on track for an initial round of
-stabilizations in Rust 1.39 (tracking issue: [rust-lang/rust#62149]), but this
-does not include support for async fn in traits. Trying to include an async fn
-in a trait produces the following error:
-
-[rust-lang/rust#62149]: https://github.com/rust-lang/rust/issues/62149
+The initial round of stabilizations for the async/await language feature in Rust
+1.39 did not include support for async fn in traits. Trying to include an async
+fn in a trait produces the following error:
```rust
trait MyTrait {
@@ -91,14 +89,14 @@
of `unsafe` in the expanded code, so rest assured that if your code compiles it
can't be that badly broken.
-- :thumbsup: Self by value, by reference, by mut reference, or no self;
-- :thumbsup: Any number of arguments, any return value;
-- :thumbsup: Generic type parameters and lifetime parameters;
-- :thumbsup: Associated types;
-- :thumbsup: Having async and non-async functions in the same trait;
-- :thumbsup: Default implementations provided by the trait;
-- :thumbsup: Elided lifetimes;
-- :thumbsup: Dyn-capable traits.
+- 👍 Self by value, by reference, by mut reference, or no self;
+- 👍 Any number of arguments, any return value;
+- 👍 Generic type parameters and lifetime parameters;
+- 👍 Associated types;
+- 👍 Having async and non-async functions in the same trait;
+- 👍 Default implementations provided by the trait;
+- 👍 Elided lifetimes;
+- 👍 Dyn-capable traits.
<br>
diff --git a/third_party/rust_crates/vendor/async-trait/src/expand.rs b/third_party/rust_crates/vendor/async-trait/src/expand.rs
index 7cc57222..2435d0a 100644
--- a/third_party/rust_crates/vendor/async-trait/src/expand.rs
+++ b/third_party/rust_crates/vendor/async-trait/src/expand.rs
@@ -10,7 +10,7 @@
use syn::visit_mut::VisitMut;
use syn::{
parse_quote, Block, FnArg, GenericParam, Generics, Ident, ImplItem, Lifetime, Pat, PatIdent,
- Path, Receiver, ReturnType, Signature, Token, TraitItem, Type, TypeParam, TypeParamBound,
+ Path, Receiver, ReturnType, Signature, Stmt, Token, TraitItem, Type, TypeParam, TypeParamBound,
WhereClause,
};
@@ -25,16 +25,8 @@
#[derive(Clone, Copy)]
enum Context<'a> {
- Trait {
- name: &'a Ident,
- generics: &'a Generics,
- supertraits: &'a Supertraits,
- },
- Impl {
- impl_generics: &'a Generics,
- receiver: &'a Type,
- as_trait: &'a Path,
- },
+ Trait { name: &'a Ident, generics: &'a Generics, supertraits: &'a Supertraits },
+ Impl { impl_generics: &'a Generics, receiver: &'a Type, as_trait: &'a Path },
}
impl Context<'_> {
@@ -75,11 +67,19 @@
}
let has_default = method.default.is_some();
transform_sig(context, sig, has_self, has_default, is_local);
+ method.attrs.push(parse_quote!(#[must_use]));
}
}
}
}
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 context = Context::Impl {
impl_generics: &input.generics,
receiver: &input.self_ty,
@@ -127,7 +127,7 @@
ReturnType::Type(_, ret) => quote!(#ret),
};
- let mut lifetimes = CollectLifetimes::new();
+ let mut lifetimes = CollectLifetimes::new("'life");
for arg in sig.inputs.iter_mut() {
match arg {
FnArg::Receiver(arg) => lifetimes.visit_receiver_mut(arg),
@@ -135,49 +135,43 @@
}
}
- let where_clause = sig
- .generics
- .where_clause
- .get_or_insert_with(|| WhereClause {
- where_token: Default::default(),
- predicates: Punctuated::new(),
- });
- for param in sig
- .generics
- .params
- .iter()
- .chain(context.lifetimes(&lifetimes.explicit))
- {
+ let where_clause = sig.generics.where_clause.get_or_insert_with(|| WhereClause {
+ where_token: Default::default(),
+ predicates: Punctuated::new(),
+ });
+ for param in sig.generics.params.iter().chain(context.lifetimes(&lifetimes.explicit)) {
match param {
GenericParam::Type(param) => {
let param = ¶m.ident;
- where_clause
- .predicates
- .push(parse_quote!(#param: 'async_trait));
+ where_clause.predicates.push(parse_quote!(#param: 'async_trait));
}
GenericParam::Lifetime(param) => {
let param = ¶m.lifetime;
- where_clause
- .predicates
- .push(parse_quote!(#param: 'async_trait));
+ where_clause.predicates.push(parse_quote!(#param: 'async_trait));
}
GenericParam::Const(_) => {}
}
}
for elided in lifetimes.elided {
sig.generics.params.push(parse_quote!(#elided));
- where_clause
- .predicates
- .push(parse_quote!(#elided: 'async_trait));
+ where_clause.predicates.push(parse_quote!(#elided: 'async_trait));
}
sig.generics.params.push(parse_quote!('async_trait));
if has_self {
let bound: Ident = match sig.inputs.iter().next() {
- Some(FnArg::Receiver(Receiver {
- reference: Some(_),
- mutability: None,
- ..
- })) => parse_quote!(Sync),
+ Some(FnArg::Receiver(Receiver { reference: Some(_), mutability: None, .. })) => {
+ parse_quote!(Sync)
+ }
+ Some(FnArg::Typed(arg))
+ if match (arg.pat.as_ref(), arg.ty.as_ref()) {
+ (Pat::Ident(pat), Type::Reference(ty)) => {
+ pat.ident == "self" && ty.mutability.is_none()
+ }
+ _ => false,
+ } =>
+ {
+ parse_quote!(Sync)
+ }
_ => parse_quote!(Send),
};
let assume_bound = match context {
@@ -193,9 +187,7 @@
for (i, arg) in sig.inputs.iter_mut().enumerate() {
match arg {
- FnArg::Receiver(Receiver {
- reference: Some(_), ..
- }) => {}
+ FnArg::Receiver(Receiver { reference: Some(_), .. }) => {}
FnArg::Receiver(arg) => arg.mutability = None,
FnArg::Typed(arg) => {
if let Pat::Ident(ident) = &mut *arg.pat {
@@ -209,11 +201,8 @@
}
}
- let bounds = if is_local {
- quote!('async_trait)
- } else {
- quote!(::core::marker::Send + 'async_trait)
- };
+ let bounds =
+ if is_local { quote!('async_trait) } else { quote!(::core::marker::Send + 'async_trait) };
sig.output = parse_quote! {
-> ::core::pin::Pin<Box<
@@ -239,18 +228,15 @@
has_self: bool,
is_local: bool,
) {
- if cfg!(feature = "support_old_nightly") {
- let brace = block.brace_token;
- *block = parse_quote!({
- Box::pin(async move #block)
- });
- block.brace_token = brace;
- return;
+ if let Some(Stmt::Item(syn::Item::Verbatim(item))) = block.stmts.first() {
+ if block.stmts.len() == 1 && item.to_string() == ";" {
+ return;
+ }
}
let inner = format_ident!("__{}", sig.ident);
let args = sig.inputs.iter().enumerate().map(|(i, arg)| match arg {
- FnArg::Receiver(_) => quote!(self),
+ FnArg::Receiver(Receiver { self_token, .. }) => quote!(#self_token),
FnArg::Typed(arg) => {
if let Pat::Ident(PatIdent { ident, .. }) = &*arg.pat {
quote!(#ident)
@@ -271,17 +257,18 @@
let mut outer_generics = generics.clone();
if !has_self {
if let Some(mut where_clause) = outer_generics.where_clause {
- where_clause.predicates = where_clause
- .predicates
- .into_iter()
- .filter_map(|mut pred| {
- if has_self_in_where_predicate(&mut pred) {
- None
- } else {
- Some(pred)
- }
- })
- .collect();
+ where_clause.predicates =
+ where_clause
+ .predicates
+ .into_iter()
+ .filter_map(|mut pred| {
+ if has_self_in_where_predicate(&mut pred) {
+ None
+ } else {
+ Some(pred)
+ }
+ })
+ .collect();
outer_generics.where_clause = Some(where_clause);
}
}
@@ -289,30 +276,19 @@
let fn_generics = mem::replace(&mut standalone.generics, outer_generics);
standalone.generics.params.extend(fn_generics.params);
if let Some(where_clause) = fn_generics.where_clause {
- standalone
- .generics
- .make_where_clause()
- .predicates
- .extend(where_clause.predicates);
+ standalone.generics.make_where_clause().predicates.extend(where_clause.predicates);
}
if has_async_lifetime(&mut standalone, block) {
standalone.generics.params.push(parse_quote!('async_trait));
}
- let mut types = standalone
- .generics
- .type_params()
- .map(|param| param.ident.clone())
- .collect::<Vec<_>>();
+ let mut types =
+ standalone.generics.type_params().map(|param| param.ident.clone()).collect::<Vec<_>>();
let mut self_bound = None::<TypeParamBound>;
match standalone.inputs.iter_mut().next() {
- Some(
- arg @ FnArg::Receiver(Receiver {
- reference: Some(_), ..
- }),
- ) => {
+ Some(arg @ FnArg::Receiver(Receiver { reference: Some(_), .. })) => {
let (lifetime, mutability, self_token) = match arg {
FnArg::Receiver(Receiver {
reference: Some((_, lifetime)),
@@ -334,19 +310,26 @@
};
}
Context::Impl { receiver, .. } => {
+ let mut ty = quote!(#receiver);
+ if let Type::TraitObject(trait_object) = receiver {
+ if trait_object.dyn_token.is_none() {
+ ty = quote!(dyn #ty);
+ }
+ if trait_object.bounds.len() > 1 {
+ ty = quote!((#ty));
+ }
+ }
*arg = parse_quote! {
- #under_self: &#lifetime #mutability #receiver
+ #under_self: &#lifetime #mutability #ty
};
}
}
}
Some(arg @ FnArg::Receiver(_)) => {
let (self_token, mutability) = match arg {
- FnArg::Receiver(Receiver {
- self_token,
- mutability,
- ..
- }) => (self_token, mutability),
+ FnArg::Receiver(Receiver { self_token, mutability, .. }) => {
+ (self_token, mutability)
+ }
_ => unreachable!(),
};
let under_self = Ident::new("_self", self_token.span);
@@ -381,10 +364,7 @@
if !is_local {
self_param.bounds.extend(self_bound);
}
- standalone
- .generics
- .params
- .push(GenericParam::Type(self_param));
+ standalone.generics.params.push(GenericParam::Type(self_param));
types.push(Ident::new("Self", Span::call_site()));
}
}
@@ -398,24 +378,31 @@
let mut replace = match context {
Context::Trait { .. } => ReplaceReceiver::with(parse_quote!(AsyncTrait)),
- Context::Impl {
- receiver, as_trait, ..
- } => ReplaceReceiver::with_as_trait(receiver.clone(), as_trait.clone()),
+ Context::Impl { receiver, as_trait, .. } => {
+ ReplaceReceiver::with_as_trait(receiver.clone(), as_trait.clone())
+ }
};
replace.visit_signature_mut(&mut standalone);
replace.visit_block_mut(block);
let mut generics = types;
- let consts = standalone
- .generics
- .const_params()
- .map(|param| param.ident.clone());
+ let consts = standalone.generics.const_params().map(|param| param.ident.clone());
generics.extend(consts);
+ let allow_non_snake_case = if sig.ident != sig.ident.to_string().to_lowercase() {
+ Some(quote!(non_snake_case,))
+ } else {
+ None
+ };
+
let brace = block.brace_token;
let box_pin = quote_spanned!(brace.span=> {
#[allow(
+ #allow_non_snake_case
clippy::missing_docs_in_private_items,
+ clippy::needless_lifetimes,
+ clippy::ptr_arg,
+ clippy::type_repetition_in_bounds,
clippy::used_underscore_binding,
)]
#standalone #block
diff --git a/third_party/rust_crates/vendor/async-trait/src/lib.rs b/third_party/rust_crates/vendor/async-trait/src/lib.rs
index 20af33e..f0102d8 100644
--- a/third_party/rust_crates/vendor/async-trait/src/lib.rs
+++ b/third_party/rust_crates/vendor/async-trait/src/lib.rs
@@ -1,11 +1,16 @@
+//! [![github]](https://github.com/dtolnay/async-trait) [![crates-io]](https://crates.io/crates/async-trait) [![docs-rs]](https://docs.rs/async-trait)
+//!
+//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
+//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
+//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K
+//!
+//! <br>
+//!
//! <h5>Type erasure for async trait methods</h5>
//!
-//! The async/await language feature is on track for an initial round of
-//! stabilizations in Rust 1.39 (tracking issue: [rust-lang/rust#62149]), but
-//! this does not include support for async fn in traits. Trying to include an
-//! async fn in a trait produces the following error:
-//!
-//! [rust-lang/rust#62149]: https://github.com/rust-lang/rust/issues/62149
+//! The initial round of stabilizations for the async/await language feature in
+//! Rust 1.39 did not include support for async fn in traits. Trying to include
+//! an async fn in a trait produces the following error:
//!
//! ```compile_fail
//! trait MyTrait {
@@ -305,6 +310,7 @@
mod lifetime;
mod parse;
mod receiver;
+mod respan;
use crate::args::Args;
use crate::expand::expand;
diff --git a/third_party/rust_crates/vendor/async-trait/src/lifetime.rs b/third_party/rust_crates/vendor/async-trait/src/lifetime.rs
index d15a4fc..0ff1588 100644
--- a/third_party/rust_crates/vendor/async-trait/src/lifetime.rs
+++ b/third_party/rust_crates/vendor/async-trait/src/lifetime.rs
@@ -24,14 +24,12 @@
pub struct CollectLifetimes {
pub elided: Vec<Lifetime>,
pub explicit: Vec<Lifetime>,
+ pub name: &'static str,
}
impl CollectLifetimes {
- pub fn new() -> Self {
- CollectLifetimes {
- elided: Vec::new(),
- explicit: Vec::new(),
- }
+ pub fn new(name: &'static str) -> Self {
+ CollectLifetimes { elided: Vec::new(), explicit: Vec::new(), name }
}
fn visit_opt_lifetime(&mut self, lifetime: &mut Option<Lifetime>) {
@@ -50,7 +48,7 @@
}
fn next_lifetime(&mut self) -> Lifetime {
- let name = format!("'life{}", self.elided.len());
+ let name = format!("{}{}", self.name, self.elided.len());
let life = Lifetime::new(&name, Span::call_site());
self.elided.push(life.clone());
life
diff --git a/third_party/rust_crates/vendor/async-trait/src/parse.rs b/third_party/rust_crates/vendor/async-trait/src/parse.rs
index 957e714..ebd2535 100644
--- a/third_party/rust_crates/vendor/async-trait/src/parse.rs
+++ b/third_party/rust_crates/vendor/async-trait/src/parse.rs
@@ -2,14 +2,6 @@
use syn::parse::{Error, Parse, ParseStream, Result};
use syn::{Attribute, ItemImpl, ItemTrait, Token};
-pub struct Nothing;
-
-impl Parse for Nothing {
- fn parse(_input: ParseStream) -> Result<Self> {
- Ok(Nothing)
- }
-}
-
pub enum Item {
Trait(ItemTrait),
Impl(ItemImpl),
diff --git a/third_party/rust_crates/vendor/async-trait/src/receiver.rs b/third_party/rust_crates/vendor/async-trait/src/receiver.rs
index a444106..2cd9f8a 100644
--- a/third_party/rust_crates/vendor/async-trait/src/receiver.rs
+++ b/third_party/rust_crates/vendor/async-trait/src/receiver.rs
@@ -1,10 +1,14 @@
-use proc_macro2::{Group, TokenStream, TokenTree};
+use crate::respan::respan;
+use proc_macro2::{Group, Spacing, Span, TokenStream, TokenTree};
+use quote::{quote, quote_spanned};
+use std::iter::FromIterator;
use std::mem;
use syn::punctuated::Punctuated;
use syn::visit_mut::{self, VisitMut};
use syn::{
- parse_quote, Block, Error, ExprPath, ExprStruct, Ident, Item, Macro, Path, PathArguments,
- QSelf, Receiver, Signature, Type, TypePath, WherePredicate,
+ parse_quote, Block, Error, ExprPath, ExprStruct, Ident, Item, Macro, PatPath, PatStruct,
+ PatTupleStruct, Path, PathArguments, QSelf, Receiver, Signature, Token, Type, TypePath,
+ WherePredicate,
};
pub fn has_self_in_sig(sig: &mut Signature) -> bool {
@@ -33,6 +37,11 @@
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);
@@ -54,17 +63,15 @@
impl ReplaceReceiver {
pub fn with(ty: Type) -> Self {
- ReplaceReceiver {
- with: ty,
- as_trait: None,
- }
+ ReplaceReceiver { with: ty, as_trait: None }
}
pub fn with_as_trait(ty: Type, as_trait: Path) -> Self {
- ReplaceReceiver {
- with: ty,
- as_trait: Some(as_trait),
- }
+ ReplaceReceiver { with: ty, as_trait: Some(as_trait) }
+ }
+
+ fn self_ty(&self, span: Span) -> Type {
+ respan(&self.with, span)
}
fn self_to_qself_type(&self, qself: &mut Option<QSelf>, path: &mut Path) {
@@ -92,12 +99,13 @@
return;
}
+ let span = first.ident.span();
*qself = Some(QSelf {
- lt_token: Default::default(),
- ty: Box::new(self.with.clone()),
+ lt_token: Token![<](span),
+ ty: Box::new(self.self_ty(span)),
position: 0,
as_token: None,
- gt_token: Default::default(),
+ gt_token: Token![>](span),
});
if include_as_trait && self.as_trait.is_some() {
@@ -117,8 +125,17 @@
}
fn self_to_expr_path(&self, path: &mut Path) {
- if let Type::Path(with) = &self.with {
- *path = with.path.clone();
+ if path.leading_colon.is_some() {
+ return;
+ }
+
+ let first = &path.segments[0];
+ if first.ident != "Self" || !first.arguments.is_empty() {
+ return;
+ }
+
+ if let Type::Path(self_ty) = self.self_ty(first.ident.span()) {
+ let variant = mem::replace(path, self_ty.path);
for segment in &mut path.segments {
if let PathArguments::AngleBracketed(bracketed) = &mut segment.arguments {
if bracketed.colon2_token.is_none() && !bracketed.args.is_empty() {
@@ -126,6 +143,10 @@
}
}
}
+ if variant.segments.len() > 1 {
+ path.segments.push_punct(Default::default());
+ path.segments.extend(variant.segments.into_pairs().skip(1));
+ }
} else {
let span = path.segments[0].ident.span();
let msg = "Self type of this impl is unsupported in expression position";
@@ -133,6 +154,58 @@
*path = parse_quote!(::core::marker::PhantomData::<#error>);
}
}
+
+ fn visit_token_stream(&self, tokens: &mut TokenStream) -> bool {
+ let mut out = Vec::new();
+ let mut modified = false;
+ let mut iter = tokens.clone().into_iter().peekable();
+ while let Some(tt) = iter.next() {
+ match tt {
+ TokenTree::Ident(mut ident) => {
+ modified |= prepend_underscore_to_self(&mut ident);
+ if ident == "Self" {
+ modified = true;
+ if self.as_trait.is_none() {
+ let ident = Ident::new("AsyncTrait", ident.span());
+ out.push(TokenTree::Ident(ident));
+ } else {
+ let self_ty = self.self_ty(ident.span());
+ match iter.peek() {
+ Some(TokenTree::Punct(p))
+ if p.as_char() == ':' && p.spacing() == Spacing::Joint =>
+ {
+ let next = iter.next().unwrap();
+ match iter.peek() {
+ Some(TokenTree::Punct(p)) if p.as_char() == ':' => {
+ let span = ident.span();
+ out.extend(quote_spanned!(span=> <#self_ty>));
+ }
+ _ => out.extend(quote!(#self_ty)),
+ }
+ out.push(next);
+ }
+ _ => out.extend(quote!(#self_ty)),
+ }
+ }
+ } else {
+ out.push(TokenTree::Ident(ident));
+ }
+ }
+ TokenTree::Group(group) => {
+ let mut content = group.stream();
+ modified |= self.visit_token_stream(&mut content);
+ let mut new = Group::new(group.delimiter(), content);
+ new.set_span(group.span());
+ out.push(TokenTree::Group(new));
+ }
+ other => out.push(other),
+ }
+ }
+ if modified {
+ *tokens = TokenStream::from_iter(out);
+ }
+ modified
+ }
}
impl VisitMut for ReplaceReceiver {
@@ -140,7 +213,7 @@
fn visit_type_mut(&mut self, ty: &mut Type) {
if let Type::Path(node) = ty {
if node.qself.is_none() && node.path.is_ident("Self") {
- *ty = self.with.clone();
+ *ty = self.self_ty(node.path.segments[0].ident.span());
} else {
self.visit_type_path_mut(node);
}
@@ -167,14 +240,36 @@
}
fn visit_expr_struct_mut(&mut self, expr: &mut ExprStruct) {
- if expr.path.is_ident("Self") {
- self.self_to_expr_path(&mut expr.path);
- }
+ self.self_to_expr_path(&mut expr.path);
visit_mut::visit_expr_struct_mut(self, expr);
}
- fn visit_item_mut(&mut self, _: &mut Item) {
- // Do not recurse into nested items.
+ fn visit_pat_path_mut(&mut self, pat: &mut PatPath) {
+ if pat.qself.is_none() {
+ self.self_to_qself_expr(&mut pat.qself, &mut pat.path);
+ }
+ visit_mut::visit_pat_path_mut(self, pat);
+ }
+
+ fn visit_pat_struct_mut(&mut self, pat: &mut PatStruct) {
+ self.self_to_expr_path(&mut pat.path);
+ visit_mut::visit_pat_struct_mut(self, pat);
+ }
+
+ fn visit_pat_tuple_struct_mut(&mut self, pat: &mut PatTupleStruct) {
+ self.self_to_expr_path(&mut pat.path);
+ visit_mut::visit_pat_tuple_struct_mut(self, pat);
+ }
+
+ fn visit_item_mut(&mut self, i: &mut Item) {
+ match i {
+ // Visit `macro_rules!` because locally defined macros can refer to `self`.
+ Item::Macro(i) if i.mac.path.is_ident("macro_rules") => {
+ self.visit_macro_mut(&mut i.mac)
+ }
+ // Otherwise, do not recurse into nested items.
+ _ => {}
+ }
}
fn visit_macro_mut(&mut self, i: &mut Macro) {
@@ -184,7 +279,7 @@
// `fn`, then `self` is more likely to refer to something other than the
// outer function's self argument.
if !contains_fn(i.tokens.clone()) {
- i.tokens = fold_token_stream(i.tokens.clone());
+ self.visit_token_stream(&mut i.tokens);
}
}
}
@@ -197,25 +292,10 @@
})
}
-fn fold_token_stream(tokens: TokenStream) -> TokenStream {
- tokens
- .into_iter()
- .map(|tt| match tt {
- TokenTree::Ident(mut ident) => {
- prepend_underscore_to_self(&mut ident);
- TokenTree::Ident(ident)
- }
- TokenTree::Group(group) => {
- let content = fold_token_stream(group.stream());
- TokenTree::Group(Group::new(group.delimiter(), content))
- }
- other => other,
- })
- .collect()
-}
-
-fn prepend_underscore_to_self(ident: &mut Ident) {
- if ident == "self" {
+fn prepend_underscore_to_self(ident: &mut Ident) -> bool {
+ let modified = ident == "self";
+ if modified {
*ident = Ident::new("_self", ident.span());
}
+ modified
}
diff --git a/third_party/rust_crates/vendor/async-trait/src/respan.rs b/third_party/rust_crates/vendor/async-trait/src/respan.rs
new file mode 100644
index 0000000..38f6612
--- /dev/null
+++ b/third_party/rust_crates/vendor/async-trait/src/respan.rs
@@ -0,0 +1,22 @@
+use proc_macro2::{Span, TokenStream};
+use quote::ToTokens;
+use syn::parse::Parse;
+
+pub(crate) fn respan<T>(node: &T, span: Span) -> T
+where
+ T: ToTokens + Parse,
+{
+ let tokens = node.to_token_stream();
+ let respanned = respan_tokens(tokens, span);
+ syn::parse2(respanned).unwrap()
+}
+
+fn respan_tokens(tokens: TokenStream, span: Span) -> TokenStream {
+ tokens
+ .into_iter()
+ .map(|mut token| {
+ token.set_span(span);
+ token
+ })
+ .collect()
+}
diff --git a/third_party/rust_crates/vendor/async-trait/tests/test.rs b/third_party/rust_crates/vendor/async-trait/tests/test.rs
index db065a9c..3ea2d15 100644
--- a/third_party/rust_crates/vendor/async-trait/tests/test.rs
+++ b/third_party/rust_crates/vendor/async-trait/tests/test.rs
@@ -416,14 +416,163 @@
impl StaticWithWhereSelf for Struct {}
}
+// https://github.com/dtolnay/async-trait/issues/45
+pub mod issue45 {
+ use crate::executor;
+ use async_trait::async_trait;
+ use std::fmt::Debug;
+ use std::sync::atomic::{AtomicU64, Ordering};
+ use std::sync::{Arc, Mutex};
+ use tracing::event::Event;
+ use tracing::field::{Field, Visit};
+ use tracing::span::{Attributes, Id, Record};
+ use tracing::{info, instrument, subscriber, Metadata, Subscriber};
+
+ #[async_trait]
+ pub trait Parent {
+ async fn foo(&mut self, v: usize);
+ }
+
+ #[async_trait]
+ pub trait Child {
+ async fn bar(&self);
+ }
+
+ #[derive(Debug)]
+ struct Impl(usize);
+
+ #[async_trait]
+ impl Parent for Impl {
+ #[instrument]
+ async fn foo(&mut self, v: usize) {
+ self.0 = v;
+ self.bar().await;
+ }
+ }
+
+ #[async_trait]
+ impl Child for Impl {
+ // Let's check that tracing detects the renaming of the `self` variable
+ // too, as tracing::instrument is not going to be able to skip the
+ // `self` argument if it can't find it in the function signature.
+ #[instrument(skip(self))]
+ async fn bar(&self) {
+ info!(val = self.0);
+ }
+ }
+
+ // A simple subscriber implementation to test the behavior of async-trait
+ // with tokio-rs/tracing. This implementation is not robust against race
+ // conditions, but it's not an issue here as we are only polling on a single
+ // future at a time.
+ #[derive(Debug)]
+ struct SubscriberInner {
+ current_depth: AtomicU64,
+ // We assert that nested functions work. If the fix were to break, we
+ // would see two top-level functions instead of `bar` nested in `foo`.
+ max_depth: AtomicU64,
+ max_span_id: AtomicU64,
+ // Name of the variable / value / depth when the event was recorded.
+ value: Mutex<Option<(&'static str, u64, u64)>>,
+ }
+
+ #[derive(Debug, Clone)]
+ struct TestSubscriber {
+ inner: Arc<SubscriberInner>,
+ }
+
+ impl TestSubscriber {
+ fn new() -> Self {
+ TestSubscriber {
+ inner: Arc::new(SubscriberInner {
+ current_depth: AtomicU64::new(0),
+ max_depth: AtomicU64::new(0),
+ max_span_id: AtomicU64::new(1),
+ value: Mutex::new(None),
+ }),
+ }
+ }
+ }
+
+ struct U64Visitor(Option<(&'static str, u64)>);
+
+ impl Visit for U64Visitor {
+ fn record_debug(&mut self, _field: &Field, _value: &dyn Debug) {}
+
+ fn record_u64(&mut self, field: &Field, value: u64) {
+ self.0 = Some((field.name(), value));
+ }
+ }
+
+ impl Subscriber for TestSubscriber {
+ fn enabled(&self, _metadata: &Metadata) -> bool {
+ true
+ }
+ fn new_span(&self, _span: &Attributes) -> Id {
+ Id::from_u64(self.inner.max_span_id.fetch_add(1, Ordering::AcqRel))
+ }
+ fn record(&self, _span: &Id, _values: &Record) {}
+ fn record_follows_from(&self, _span: &Id, _follows: &Id) {}
+ fn event(&self, event: &Event) {
+ let mut visitor = U64Visitor(None);
+ event.record(&mut visitor);
+ if let Some((s, v)) = visitor.0 {
+ let current_depth = self.inner.current_depth.load(Ordering::Acquire);
+ *self.inner.value.lock().unwrap() = Some((s, v, current_depth));
+ }
+ }
+ fn enter(&self, _span: &Id) {
+ let old_depth = self.inner.current_depth.fetch_add(1, Ordering::AcqRel);
+ if old_depth + 1 > self.inner.max_depth.load(Ordering::Acquire) {
+ self.inner.max_depth.fetch_add(1, Ordering::AcqRel);
+ }
+ }
+ fn exit(&self, _span: &Id) {
+ self.inner.current_depth.fetch_sub(1, Ordering::AcqRel);
+ }
+ }
+
+ #[test]
+ fn tracing() {
+ // Create the future outside of the subscriber, as no call to tracing
+ // should be made until the future is polled.
+ let mut struct_impl = Impl(0);
+ let fut = struct_impl.foo(5);
+ let subscriber = TestSubscriber::new();
+ subscriber::with_default(subscriber.clone(), || executor::block_on_simple(fut));
+ // Did we enter bar inside of foo?
+ assert_eq!(subscriber.inner.max_depth.load(Ordering::Acquire), 2);
+ // Have we exited all spans?
+ assert_eq!(subscriber.inner.current_depth.load(Ordering::Acquire), 0);
+ // Did we create only two spans? Note: spans start at 1, hence the -1.
+ assert_eq!(subscriber.inner.max_span_id.load(Ordering::Acquire) - 1, 2);
+ // Was the value recorded at the right depth i.e. in the right function?
+ // If so, was it the expected value?
+ assert_eq!(*subscriber.inner.value.lock().unwrap(), Some(("val", 5, 2)));
+ }
+}
+
// https://github.com/dtolnay/async-trait/issues/46
pub mod issue46 {
use async_trait::async_trait;
- macro_rules! implement_commands {
+ macro_rules! implement_commands_workaround {
($tyargs:tt : $ty:tt) => {
#[async_trait]
- pub trait AsyncCommands: Sized {
+ pub trait AsyncCommands1: Sized {
+ async fn f<$tyargs: $ty>(&mut self, x: $tyargs) {
+ self.f(x).await
+ }
+ }
+ };
+ }
+
+ implement_commands_workaround!(K: Send);
+
+ macro_rules! implement_commands {
+ ($tyargs:ident : $ty:ident) => {
+ #[async_trait]
+ pub trait AsyncCommands2: Sized {
async fn f<$tyargs: $ty>(&mut self, x: $tyargs) {
self.f(x).await
}
@@ -502,3 +651,311 @@
executor::block_on_simple(fut);
}
}
+
+// 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) {
+ macro_rules! t {
+ () => {{
+ let _: &Self = self;
+ }};
+ }
+ t!();
+ }
+ }
+}
+
+// https://github.com/dtolnay/async-trait/issues/73
+pub mod issue73 {
+ use async_trait::async_trait;
+
+ #[async_trait]
+ pub trait Example {
+ const ASSOCIATED: &'static str;
+
+ async fn associated(&self) {
+ println!("Associated:{}", Self::ASSOCIATED);
+ }
+ }
+}
+
+// https://github.com/dtolnay/async-trait/issues/81
+pub mod issue81 {
+ use async_trait::async_trait;
+
+ #[async_trait]
+ pub trait Trait {
+ async fn handle(&self);
+ }
+
+ pub enum Enum {
+ Variant,
+ }
+
+ #[async_trait]
+ impl Trait for Enum {
+ async fn handle(&self) {
+ let Enum::Variant = self;
+ let Self::Variant = self;
+ }
+ }
+}
+
+// https://github.com/dtolnay/async-trait/issues/83
+pub mod issue83 {
+ use async_trait::async_trait;
+
+ #[async_trait]
+ pub trait Trait {
+ async fn f(&self) {}
+ async fn g(self: &Self) {}
+ }
+}
+
+// https://github.com/dtolnay/async-trait/issues/85
+pub mod issue85 {
+ #![deny(non_snake_case)]
+
+ use async_trait::async_trait;
+
+ #[async_trait]
+ pub trait Trait {
+ #[allow(non_snake_case)]
+ async fn camelCase();
+ }
+
+ pub struct Struct;
+
+ #[async_trait]
+ impl Trait for Struct {
+ async fn camelCase() {}
+ }
+}
+
+// https://github.com/dtolnay/async-trait/issues/87
+pub mod issue87 {
+ use async_trait::async_trait;
+
+ #[async_trait]
+ pub trait Trait {
+ async fn f(&self);
+ }
+
+ pub enum Tuple {
+ V(),
+ }
+
+ pub enum Struct {
+ V {},
+ }
+
+ #[async_trait]
+ impl Trait for Tuple {
+ async fn f(&self) {
+ let Tuple::V() = self;
+ let Self::V() = self;
+ let _ = Self::V;
+ let _ = Self::V();
+ }
+ }
+
+ #[async_trait]
+ impl Trait for Struct {
+ async fn f(&self) {
+ let Struct::V {} = self;
+ let Self::V {} = self;
+ let _ = Self::V {};
+ }
+ }
+}
+
+// https://github.com/dtolnay/async-trait/issues/89
+pub mod issue89 {
+ #![allow(bare_trait_objects)]
+
+ use async_trait::async_trait;
+
+ #[async_trait]
+ trait Trait {
+ async fn f(&self);
+ }
+
+ #[async_trait]
+ impl Trait for Send + Sync {
+ async fn f(&self) {}
+ }
+
+ #[async_trait]
+ impl Trait for dyn Fn(i8) + Send + Sync {
+ async fn f(&self) {}
+ }
+
+ #[async_trait]
+ impl Trait for (dyn Fn(u8) + Send + Sync) {
+ async fn f(&self) {}
+ }
+}
+
+// https://github.com/dtolnay/async-trait/issues/92
+pub mod issue92 {
+ use async_trait::async_trait;
+
+ macro_rules! mac {
+ ($($tt:tt)*) => {
+ $($tt)*
+ };
+ }
+
+ pub struct Struct<T> {
+ _x: T,
+ }
+
+ impl<T> Struct<T> {
+ const ASSOCIATED1: &'static str = "1";
+ async fn associated1() {}
+ }
+
+ #[async_trait]
+ pub trait Trait
+ where
+ mac!(Self): Send,
+ {
+ const ASSOCIATED2: &'static str;
+ type Associated2;
+
+ #[allow(path_statements, clippy::no_effect)]
+ async fn associated2(&self) {
+ // trait items
+ mac!(let _: Self::Associated2;);
+ mac!(let _: <Self>::Associated2;);
+ mac!(let _: <Self as Trait>::Associated2;);
+ mac!(Self::ASSOCIATED2;);
+ mac!(<Self>::ASSOCIATED2;);
+ mac!(<Self as Trait>::ASSOCIATED2;);
+ mac!(let _ = Self::associated2(self););
+ mac!(let _ = <Self>::associated2(self););
+ mac!(let _ = <Self as Trait>::associated2(self););
+ }
+ }
+
+ #[async_trait]
+ impl<T: Send + Sync> Trait for Struct<T>
+ where
+ mac!(Self): Send,
+ {
+ const ASSOCIATED2: &'static str = "2";
+ type Associated2 = ();
+
+ #[allow(path_statements, clippy::no_effect)]
+ async fn associated2(&self) {
+ // inherent items
+ mac!(Self::ASSOCIATED1;);
+ mac!(<Self>::ASSOCIATED1;);
+ mac!(let _ = Self::associated1(););
+ mac!(let _ = <Self>::associated1(););
+
+ // trait items
+ mac!(let _: <Self as Trait>::Associated2;);
+ mac!(Self::ASSOCIATED2;);
+ mac!(<Self>::ASSOCIATED2;);
+ mac!(<Self as Trait>::ASSOCIATED2;);
+ mac!(let _ = Self::associated2(self););
+ mac!(let _ = <Self>::associated2(self););
+ mac!(let _ = <Self as Trait>::associated2(self););
+ }
+ }
+
+ pub struct Unit;
+
+ #[async_trait]
+ impl Trait for Unit {
+ const ASSOCIATED2: &'static str = "2";
+ type Associated2 = ();
+
+ async fn associated2(&self) {
+ mac!(let Self: Self = *self;);
+ }
+ }
+}
+
+// https://github.com/dtolnay/async-trait/issues/104
+mod issue104 {
+ use async_trait::async_trait;
+
+ #[async_trait]
+ trait T1 {
+ async fn id(&self) -> i32;
+ }
+
+ macro_rules! impl_t1 {
+ ($ty:ty, $id:expr) => {
+ #[async_trait]
+ impl T1 for $ty {
+ async fn id(&self) -> i32 {
+ $id
+ }
+ }
+ };
+ }
+
+ struct Foo;
+
+ impl_t1!(Foo, 1);
+}
+
+// https://github.com/dtolnay/async-trait/issues/106
+mod issue106 {
+ use async_trait::async_trait;
+ use std::future::Future;
+
+ #[async_trait]
+ pub trait ProcessPool: Send + Sync {
+ type ThreadPool;
+
+ async fn spawn<F, Fut, T>(&self, work: F) -> T
+ where
+ F: FnOnce(&Self::ThreadPool) -> Fut + Send,
+ Fut: Future<Output = T> + 'static;
+ }
+
+ #[async_trait]
+ impl<P: ?Sized> ProcessPool for &P
+ where
+ P: ProcessPool,
+ {
+ type ThreadPool = P::ThreadPool;
+
+ async fn spawn<F, Fut, T>(&self, work: F) -> T
+ where
+ F: FnOnce(&Self::ThreadPool) -> Fut + Send,
+ Fut: Future<Output = T> + 'static,
+ {
+ (**self).spawn(work).await
+ }
+ }
+}
+
+// https://github.com/dtolnay/async-trait/issues/110
+mod issue110 {
+ #![deny(clippy::all)]
+
+ use async_trait::async_trait;
+ use std::marker::PhantomData;
+
+ #[async_trait]
+ pub trait Loader {
+ async fn load(&self, key: &str);
+ }
+
+ pub struct AwsEc2MetadataLoader<'a> {
+ marker: PhantomData<&'a ()>,
+ }
+
+ #[async_trait]
+ impl Loader for AwsEc2MetadataLoader<'_> {
+ async fn load(&self, _key: &str) {}
+ }
+}
diff --git a/third_party/rust_crates/vendor/async-trait/tests/ui/bare-trait-object.rs b/third_party/rust_crates/vendor/async-trait/tests/ui/bare-trait-object.rs
new file mode 100644
index 0000000..afcd6b4
--- /dev/null
+++ b/third_party/rust_crates/vendor/async-trait/tests/ui/bare-trait-object.rs
@@ -0,0 +1,15 @@
+#![deny(bare_trait_objects)]
+
+use async_trait::async_trait;
+
+#[async_trait]
+trait Trait {
+ async fn f(&self);
+}
+
+#[async_trait]
+impl Trait for Send + Sync {
+ async fn f(&self) {}
+}
+
+fn main() {}
diff --git a/third_party/rust_crates/vendor/async-trait/tests/ui/bare-trait-object.stderr b/third_party/rust_crates/vendor/async-trait/tests/ui/bare-trait-object.stderr
new file mode 100644
index 0000000..98cf679
--- /dev/null
+++ b/third_party/rust_crates/vendor/async-trait/tests/ui/bare-trait-object.stderr
@@ -0,0 +1,11 @@
+error: trait objects without an explicit `dyn` are deprecated
+ --> $DIR/bare-trait-object.rs:11:16
+ |
+11 | impl Trait for Send + Sync {
+ | ^^^^^^^^^^^ help: use `dyn`: `dyn Send + Sync`
+ |
+note: the lint level is defined here
+ --> $DIR/bare-trait-object.rs:1:9
+ |
+1 | #![deny(bare_trait_objects)]
+ | ^^^^^^^^^^^^^^^^^^
diff --git a/third_party/rust_crates/vendor/async-trait/tests/ui/delimiter-span.rs b/third_party/rust_crates/vendor/async-trait/tests/ui/delimiter-span.rs
new file mode 100644
index 0000000..68456fa
--- /dev/null
+++ b/third_party/rust_crates/vendor/async-trait/tests/ui/delimiter-span.rs
@@ -0,0 +1,21 @@
+use async_trait::async_trait;
+
+macro_rules! picky {
+ (ident) => {};
+}
+
+#[async_trait]
+trait Trait {
+ async fn method();
+}
+
+struct Struct;
+
+#[async_trait]
+impl Trait for Struct {
+ async fn method() {
+ picky!({ 123 });
+ }
+}
+
+fn main() {}
diff --git a/third_party/rust_crates/vendor/async-trait/tests/ui/delimiter-span.stderr b/third_party/rust_crates/vendor/async-trait/tests/ui/delimiter-span.stderr
new file mode 100644
index 0000000..e080445
--- /dev/null
+++ b/third_party/rust_crates/vendor/async-trait/tests/ui/delimiter-span.stderr
@@ -0,0 +1,8 @@
+error: no rules expected the token `{`
+ --> $DIR/delimiter-span.rs:17:16
+ |
+3 | macro_rules! picky {
+ | ------------------ when calling this macro
+...
+17 | picky!({ 123 });
+ | ^ no rules expected this token in macro call
diff --git a/third_party/rust_crates/vendor/async-trait/tests/ui/missing-body.rs b/third_party/rust_crates/vendor/async-trait/tests/ui/missing-body.rs
new file mode 100644
index 0000000..f3e1126
--- /dev/null
+++ b/third_party/rust_crates/vendor/async-trait/tests/ui/missing-body.rs
@@ -0,0 +1,15 @@
+use async_trait::async_trait;
+
+#[async_trait]
+trait Trait {
+ async fn f(&self);
+}
+
+struct Thing;
+
+#[async_trait]
+impl Trait for Thing {
+ async fn f(&self);
+}
+
+fn main() {}
diff --git a/third_party/rust_crates/vendor/async-trait/tests/ui/missing-body.stderr b/third_party/rust_crates/vendor/async-trait/tests/ui/missing-body.stderr
new file mode 100644
index 0000000..2d9b09c
--- /dev/null
+++ b/third_party/rust_crates/vendor/async-trait/tests/ui/missing-body.stderr
@@ -0,0 +1,7 @@
+error: associated function in `impl` without body
+ --> $DIR/missing-body.rs:12:5
+ |
+12 | async fn f(&self);
+ | ^^^^^^^^^^^^^^^^^-
+ | |
+ | help: provide a definition for the function: `{ <body> }`
diff --git a/third_party/rust_crates/vendor/async-trait/tests/ui/must-use.rs b/third_party/rust_crates/vendor/async-trait/tests/ui/must-use.rs
new file mode 100644
index 0000000..7ad0d9b
--- /dev/null
+++ b/third_party/rust_crates/vendor/async-trait/tests/ui/must-use.rs
@@ -0,0 +1,21 @@
+#![deny(unused_must_use)]
+
+use async_trait::async_trait;
+
+#[async_trait]
+trait Interface {
+ async fn f(&self);
+}
+
+struct Thing;
+
+#[async_trait]
+impl Interface for Thing {
+ async fn f(&self) {}
+}
+
+pub async fn f() {
+ Thing.f();
+}
+
+fn main() {}
diff --git a/third_party/rust_crates/vendor/async-trait/tests/ui/must-use.stderr b/third_party/rust_crates/vendor/async-trait/tests/ui/must-use.stderr
new file mode 100644
index 0000000..c09a51e
--- /dev/null
+++ b/third_party/rust_crates/vendor/async-trait/tests/ui/must-use.stderr
@@ -0,0 +1,11 @@
+error: unused return value of `Interface::f` that must be used
+ --> $DIR/must-use.rs:18:5
+ |
+18 | Thing.f();
+ | ^^^^^^^^^^
+ |
+note: the lint level is defined here
+ --> $DIR/must-use.rs:1:9
+ |
+1 | #![deny(unused_must_use)]
+ | ^^^^^^^^^^^^^^^
diff --git a/third_party/rust_crates/vendor/async-trait/tests/ui/self-span.rs b/third_party/rust_crates/vendor/async-trait/tests/ui/self-span.rs
new file mode 100644
index 0000000..b01f247
--- /dev/null
+++ b/third_party/rust_crates/vendor/async-trait/tests/ui/self-span.rs
@@ -0,0 +1,30 @@
+use async_trait::async_trait;
+
+pub struct S {}
+
+pub enum E {
+ V {},
+}
+
+#[async_trait]
+pub trait Trait {
+ async fn method(self);
+}
+
+#[async_trait]
+impl Trait for S {
+ async fn method(self) {
+ let _: () = self;
+ let _: Self = Self;
+ }
+}
+
+#[async_trait]
+impl Trait for E {
+ async fn method(self) {
+ let _: () = self;
+ let _: Self = Self::V;
+ }
+}
+
+fn main() {}
diff --git a/third_party/rust_crates/vendor/async-trait/tests/ui/self-span.stderr b/third_party/rust_crates/vendor/async-trait/tests/ui/self-span.stderr
new file mode 100644
index 0000000..f897c01
--- /dev/null
+++ b/third_party/rust_crates/vendor/async-trait/tests/ui/self-span.stderr
@@ -0,0 +1,30 @@
+error[E0423]: expected value, found struct `S`
+ --> $DIR/self-span.rs:18:23
+ |
+3 | pub struct S {}
+ | --------------- `S` defined here
+...
+18 | let _: Self = Self;
+ | ^^^^ did you mean `S { /* fields */ }`?
+
+error[E0308]: mismatched types
+ --> $DIR/self-span.rs:17:21
+ |
+17 | let _: () = self;
+ | -- ^^^^ expected `()`, found struct `S`
+ | |
+ | expected due to this
+
+error[E0308]: mismatched types
+ --> $DIR/self-span.rs:25:21
+ |
+25 | let _: () = self;
+ | -- ^^^^ expected `()`, found enum `E`
+ | |
+ | expected due to this
+
+error[E0533]: expected unit struct, unit variant or constant, found struct variant `Self::V`
+ --> $DIR/self-span.rs:26:23
+ |
+26 | let _: Self = Self::V;
+ | ^^^^^^^
diff --git a/third_party/rust_crates/vendor/async-trait/tests/ui/send-not-implemented.stderr b/third_party/rust_crates/vendor/async-trait/tests/ui/send-not-implemented.stderr
index 4fad3a95..2f288f5 100644
--- a/third_party/rust_crates/vendor/async-trait/tests/ui/send-not-implemented.stderr
+++ b/third_party/rust_crates/vendor/async-trait/tests/ui/send-not-implemented.stderr
@@ -14,7 +14,7 @@
--> $DIR/send-not-implemented.rs:11:9
|
10 | let _guard = mutex.lock().unwrap();
- | ------ has type `std::sync::MutexGuard<'_, ()>`
+ | ------ has type `std::sync::MutexGuard<'_, ()>` which is not `Send`
11 | f().await;
| ^^^^^^^^^ await occurs here, with `_guard` maybe used later
12 | }