Skip to content

Commit

Permalink
Merge pull request #239 from dtolnay/singleuse
Browse files Browse the repository at this point in the history
Delete replacement of elided lifetimes in impl heading
  • Loading branch information
dtolnay authored Mar 4, 2023
2 parents 7937a89 + 5883ac8 commit 7eea88b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
9 changes: 1 addition & 8 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 2 additions & 4 deletions src/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ use syn::{
pub struct CollectLifetimes {
pub elided: Vec<Lifetime>,
pub explicit: Vec<Lifetime>,
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,
}
}

Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
}

0 comments on commit 7eea88b

Please sign in to comment.