From 3b78161de94175ffa72c6d3a5451415b70cace51 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 11 Feb 2025 18:21:57 -0800 Subject: [PATCH 1/9] Update ui test suite to nightly-2025-02-12 --- tests/ui/bare-trait-object.stderr | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/ui/bare-trait-object.stderr b/tests/ui/bare-trait-object.stderr index eb4d3b4..9c94b22 100644 --- a/tests/ui/bare-trait-object.stderr +++ b/tests/ui/bare-trait-object.stderr @@ -10,5 +10,6 @@ help: you can add the `dyn` keyword if you want a trait object | +++ help: alternatively use a blanket implementation to implement `Trait` for all types that also implement `Send + Sync` | -11 | impl Trait for T { - | ++++++++++++++++ ~ +11 - impl Trait for Send + Sync { +11 + impl Trait for T { + | From ea2f2a29a29b71f36479ee99d3d51953f80e44d8 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 19 Feb 2025 22:59:06 -0800 Subject: [PATCH 2/9] Point standard library links to stable --- Cargo.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index fefb0ff..973a065 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,4 +29,10 @@ trybuild = { version = "1.0.81", features = ["diff"] } [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] -rustdoc-args = ["--generate-link-to-definition"] +rustdoc-args = [ + "--generate-link-to-definition", + "--extern-html-root-url=core=https://doc.rust-lang.org", + "--extern-html-root-url=alloc=https://doc.rust-lang.org", + "--extern-html-root-url=std=https://doc.rust-lang.org", + "--extern-html-root-url=proc_macro=https://doc.rust-lang.org", +] From 45fd82a71eca47ddbd0627546fb1ba7489e51712 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 2 Mar 2025 21:12:03 -0800 Subject: [PATCH 3/9] Ignore elidable_lifetime_names pedantic clippy lint warning: the following explicit lifetimes could be elided: 'a --> src/expand.rs:445:10 | 445 | impl<'a> VisitMut for AssociatedTypeImplTraits<'a> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names = note: `-W clippy::elidable-lifetime-names` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::elidable_lifetime_names)]` help: elide the lifetimes | 445 - impl<'a> VisitMut for AssociatedTypeImplTraits<'a> { 445 + impl VisitMut for AssociatedTypeImplTraits<'_> { | warning: the following explicit lifetimes could be elided: 'a --> tests/test.rs:1432:10 | 1432 | impl<'a> Drop for IncrementOnDrop<'a> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names = note: `-W clippy::elidable-lifetime-names` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::elidable_lifetime_names)]` help: elide the lifetimes | 1432 - impl<'a> Drop for IncrementOnDrop<'a> { 1432 + impl Drop for IncrementOnDrop<'_> { | --- src/lib.rs | 1 + tests/test.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 94c538d..646916c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -218,6 +218,7 @@ #![allow( clippy::default_trait_access, clippy::doc_markdown, + clippy::elidable_lifetime_names, clippy::explicit_auto_deref, clippy::if_not_else, clippy::items_after_statements, diff --git a/tests/test.rs b/tests/test.rs index ada375d..7050260 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -4,6 +4,7 @@ )] #![deny(rust_2021_compatibility, unused_qualifications)] #![allow( + clippy::elidable_lifetime_names, clippy::incompatible_msrv, // https://github.com/rust-lang/rust-clippy/issues/12257 clippy::let_underscore_untyped, clippy::let_unit_value, From 137d14caf3fda9b066384e32e883f2c9bddcbf63 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 2 Mar 2025 21:13:10 -0800 Subject: [PATCH 4/9] Resolve mem_replace_with_default clippy lint warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> src/expand.rs:195:30 | 195 | let bounds = mem::replace(&mut param.bounds, Punctuated::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut param.bounds)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default = note: `-W clippy::mem-replace-with-default` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::mem_replace_with_default)]` warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> src/expand.rs:206:30 | 206 | let bounds = mem::replace(&mut param.bounds, Punctuated::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut param.bounds)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default --- src/expand.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/expand.rs b/src/expand.rs index 6546769..cfaa11c 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -192,7 +192,7 @@ fn transform_sig( Some(colon_token) => colon_token.span, None => param_name.span(), }; - let bounds = mem::replace(&mut param.bounds, Punctuated::new()); + let bounds = mem::take(&mut param.bounds); where_clause_or_default(&mut sig.generics.where_clause) .predicates .push(parse_quote_spanned!(span=> #param_name: 'async_trait + #bounds)); @@ -203,7 +203,7 @@ fn transform_sig( Some(colon_token) => colon_token.span, None => param_name.span(), }; - let bounds = mem::replace(&mut param.bounds, Punctuated::new()); + let bounds = mem::take(&mut param.bounds); where_clause_or_default(&mut sig.generics.where_clause) .predicates .push(parse_quote_spanned!(span=> #param: 'async_trait + #bounds)); From 32540aadec088a87eeb88f7688ec5b211a0d5167 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 2 Mar 2025 21:13:59 -0800 Subject: [PATCH 5/9] Release 0.1.87 --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 973a065..404c331 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-trait" -version = "0.1.86" +version = "0.1.87" authors = ["David Tolnay "] categories = ["asynchronous", "no-std"] description = "Type erasure for async trait methods" diff --git a/src/lib.rs b/src/lib.rs index 646916c..1a6f97a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -214,7 +214,7 @@ //! } //! ``` -#![doc(html_root_url = "https://docs.rs/async-trait/0.1.86")] +#![doc(html_root_url = "https://docs.rs/async-trait/0.1.87")] #![allow( clippy::default_trait_access, clippy::doc_markdown, From a11384eec60634098f66a3d6ac89c23beccdbbc8 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 14 Mar 2025 17:54:20 -0700 Subject: [PATCH 6/9] Add issue 283 link in test --- tests/test.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test.rs b/tests/test.rs index 7050260..1772e75 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1685,6 +1685,7 @@ pub mod issue281 { } } +// https://github.com/dtolnay/async-trait/issues/283 pub mod issue283 { use async_trait::async_trait; From 78506f17149e08594c1a120f1df828411772a0b8 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 14 Mar 2025 17:57:14 -0700 Subject: [PATCH 7/9] Add regression test for issue 288 --- tests/test.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test.rs b/tests/test.rs index 1772e75..0b6a322 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1705,3 +1705,24 @@ pub mod issue283 { } } } + +// https://github.com/dtolnay/async-trait/issues/288 +pub mod issue288 { + use async_trait::async_trait; + + #[async_trait] + pub trait Trait { + async fn f<#[cfg(any())] T: Send>(#[cfg(any())] t: T); + async fn g<#[cfg(all())] T: Send>(#[cfg(all())] t: T); + } + + pub struct Struct; + + #[async_trait] + impl Trait for Struct { + async fn f<#[cfg(any())] T: Send>(#[cfg(any())] t: T) {} + async fn g<#[cfg(all())] T: Send>(#[cfg(all())] t: T) { + let _ = t; + } + } +} From d3059849a4024425f80f0713bc802d8959290d96 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 14 Mar 2025 17:53:22 -0700 Subject: [PATCH 8/9] Fix lifetime bounding on generic parameters that have cfg --- src/expand.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/expand.rs b/src/expand.rs index cfaa11c..573ad1d 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -192,10 +192,14 @@ fn transform_sig( Some(colon_token) => colon_token.span, None => param_name.span(), }; - let bounds = mem::take(&mut param.bounds); - where_clause_or_default(&mut sig.generics.where_clause) - .predicates - .push(parse_quote_spanned!(span=> #param_name: 'async_trait + #bounds)); + if param.attrs.is_empty() { + let bounds = mem::take(&mut param.bounds); + where_clause_or_default(&mut sig.generics.where_clause) + .predicates + .push(parse_quote_spanned!(span=> #param_name: 'async_trait + #bounds)); + } else { + param.bounds.push(parse_quote!('async_trait)); + } } GenericParam::Lifetime(param) => { let param_name = ¶m.lifetime; @@ -203,10 +207,14 @@ fn transform_sig( Some(colon_token) => colon_token.span, None => param_name.span(), }; - let bounds = mem::take(&mut param.bounds); - where_clause_or_default(&mut sig.generics.where_clause) - .predicates - .push(parse_quote_spanned!(span=> #param: 'async_trait + #bounds)); + if param.attrs.is_empty() { + let bounds = mem::take(&mut param.bounds); + where_clause_or_default(&mut sig.generics.where_clause) + .predicates + .push(parse_quote_spanned!(span=> #param: 'async_trait + #bounds)); + } else { + param.bounds.push(parse_quote!('async_trait)); + } } GenericParam::Const(_) => {} } From b3a59195c29c5b336490cec1bac23cff8d3e4483 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 14 Mar 2025 17:59:58 -0700 Subject: [PATCH 9/9] Release 0.1.88 --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 404c331..20c2873 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-trait" -version = "0.1.87" +version = "0.1.88" authors = ["David Tolnay "] categories = ["asynchronous", "no-std"] description = "Type erasure for async trait methods" diff --git a/src/lib.rs b/src/lib.rs index 1a6f97a..bc9bd92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -214,7 +214,7 @@ //! } //! ``` -#![doc(html_root_url = "https://docs.rs/async-trait/0.1.87")] +#![doc(html_root_url = "https://docs.rs/async-trait/0.1.88")] #![allow( clippy::default_trait_access, clippy::doc_markdown,