Skip to content

Commit 7eea88b

Browse files
authored
Merge pull request #239 from dtolnay/singleuse
Delete replacement of elided lifetimes in impl heading
2 parents 7937a89 + 5883ac8 commit 7eea88b

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/expand.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@ pub fn expand(input: &mut Item, is_local: bool) {
8080
}
8181
}
8282
Item::Impl(input) => {
83-
let mut lifetimes = CollectLifetimes::new("'impl");
84-
lifetimes.visit_type_mut(&mut *input.self_ty);
85-
lifetimes.visit_path_mut(&mut input.trait_.as_mut().unwrap().1);
86-
let params = &input.generics.params;
87-
let elided = lifetimes.elided;
88-
input.generics.params = parse_quote!(#(#elided,)* #params);
89-
9083
let mut associated_type_impl_traits = Set::new();
9184
for inner in &input.items {
9285
if let ImplItem::Type(assoc) = inner {
@@ -167,7 +160,7 @@ fn transform_sig(
167160
ReturnType::Type(arrow, ret) => (*arrow, quote!(#ret)),
168161
};
169162

170-
let mut lifetimes = CollectLifetimes::new("'life");
163+
let mut lifetimes = CollectLifetimes::new();
171164
for arg in sig.inputs.iter_mut() {
172165
match arg {
173166
FnArg::Receiver(arg) => lifetimes.visit_receiver_mut(arg),

src/lifetime.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ use syn::{
99
pub struct CollectLifetimes {
1010
pub elided: Vec<Lifetime>,
1111
pub explicit: Vec<Lifetime>,
12-
pub name: &'static str,
1312
}
1413

1514
impl CollectLifetimes {
16-
pub fn new(name: &'static str) -> Self {
15+
pub fn new() -> Self {
1716
CollectLifetimes {
1817
elided: Vec::new(),
1918
explicit: Vec::new(),
20-
name,
2119
}
2220
}
2321

@@ -37,7 +35,7 @@ impl CollectLifetimes {
3735
}
3836

3937
fn next_lifetime(&mut self, span: Span) -> Lifetime {
40-
let name = format!("{}{}", self.name, self.elided.len());
38+
let name = format!("'life{}", self.elided.len());
4139
let life = Lifetime::new(&name, span);
4240
self.elided.push(life.clone());
4341
life

tests/test.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,3 +1585,22 @@ pub mod issue236 {
15851585
}
15861586
}
15871587
}
1588+
1589+
// https://github.com/dtolnay/async-trait/issues/238
1590+
pub mod issue238 {
1591+
#![deny(single_use_lifetimes)]
1592+
1593+
use async_trait::async_trait;
1594+
1595+
#[async_trait]
1596+
pub trait Trait {
1597+
async fn f();
1598+
}
1599+
1600+
pub struct Struct;
1601+
1602+
#[async_trait]
1603+
impl Trait for &Struct {
1604+
async fn f() {}
1605+
}
1606+
}

0 commit comments

Comments
 (0)