From b77d0d504ca3fd0ccee662a559585998f78358a1 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 6 Jan 2025 09:51:38 -0800 Subject: [PATCH 1/2] Add regression test for issue 283 error[E0276]: impl has stricter requirements than trait --> tests/test.rs:1699:5 | 1692 | async fn a(); | ------------- definition of `a` from trait ... 1699 | #[async_trait] | ^^^^^^^^^^^^^^ impl has extra requirement `T: 'async_trait` | = note: this error originates in the attribute macro `async_trait` (in Nightly builds, run with -Z macro-backtrace for more info) --- tests/test.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test.rs b/tests/test.rs index 5d1c549..89c848b 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1683,3 +1683,23 @@ pub mod issue281 { } } } + +pub mod issue283 { + use async_trait::async_trait; + + #[async_trait] + pub trait Trait { + async fn a(); + } + + pub trait Bound { + fn b(); + } + + #[async_trait] + impl Trait for T { + async fn a() { + Self::b(); + } + } +} From 9456e54b598cfe2c965170ff78308f2b6f2d6f73 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 6 Jan 2025 09:56:52 -0800 Subject: [PATCH 2/2] Omit `Self: 'async_trait` bound in impl when not needed by signature --- src/expand.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/expand.rs b/src/expand.rs index df02106..6546769 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -99,7 +99,7 @@ pub fn expand(input: &mut Item, is_local: bool) { ImplItem::Fn(method) if method.sig.asyncness.is_some() => { let sig = &mut method.sig; let block = &mut method.block; - let has_self = has_self_in_sig(sig) || has_self_in_block(block); + let has_self = has_self_in_sig(sig); transform_block(context, sig, block); transform_sig(context, sig, has_self, false, is_local); method.attrs.push(lint_suppress_with_body());