diff --git a/src/expand.rs b/src/expand.rs index 88338db..2499177 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -80,13 +80,6 @@ pub fn expand(input: &mut Item, is_local: bool) { } } 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 mut associated_type_impl_traits = Set::new(); for inner in &input.items { if let ImplItem::Type(assoc) = inner { @@ -167,7 +160,7 @@ fn transform_sig( ReturnType::Type(arrow, ret) => (*arrow, quote!(#ret)), }; - let mut lifetimes = CollectLifetimes::new("'life"); + let mut lifetimes = CollectLifetimes::new(); for arg in sig.inputs.iter_mut() { match arg { FnArg::Receiver(arg) => lifetimes.visit_receiver_mut(arg), diff --git a/src/lifetime.rs b/src/lifetime.rs index 86eac24..1e5a658 100644 --- a/src/lifetime.rs +++ b/src/lifetime.rs @@ -9,15 +9,13 @@ use syn::{ pub struct CollectLifetimes { pub elided: Vec, pub explicit: Vec, - pub name: &'static str, } impl CollectLifetimes { - pub fn new(name: &'static str) -> Self { + pub fn new() -> Self { CollectLifetimes { elided: Vec::new(), explicit: Vec::new(), - name, } } @@ -37,7 +35,7 @@ impl CollectLifetimes { } fn next_lifetime(&mut self, span: Span) -> Lifetime { - let name = format!("{}{}", self.name, self.elided.len()); + let name = format!("'life{}", self.elided.len()); let life = Lifetime::new(&name, span); self.elided.push(life.clone()); life diff --git a/tests/test.rs b/tests/test.rs index 102f97e..4fc46f0 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1585,3 +1585,22 @@ pub mod issue236 { } } } + +// https://github.com/dtolnay/async-trait/issues/238 +pub mod issue238 { + #![deny(single_use_lifetimes)] + + use async_trait::async_trait; + + #[async_trait] + pub trait Trait { + async fn f(); + } + + pub struct Struct; + + #[async_trait] + impl Trait for &Struct { + async fn f() {} + } +}