Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete replacement of elided lifetimes in impl heading #239

Merged
merged 2 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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() {}
}
}