Skip to content

Commit a306be8

Browse files
authored
Merge pull request #289 from dtolnay/cfg
Fix lifetime bounding on generic parameters that have cfg
2 parents a11384e + d305984 commit a306be8

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/expand.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,29 @@ fn transform_sig(
192192
Some(colon_token) => colon_token.span,
193193
None => param_name.span(),
194194
};
195-
let bounds = mem::take(&mut param.bounds);
196-
where_clause_or_default(&mut sig.generics.where_clause)
197-
.predicates
198-
.push(parse_quote_spanned!(span=> #param_name: 'async_trait + #bounds));
195+
if param.attrs.is_empty() {
196+
let bounds = mem::take(&mut param.bounds);
197+
where_clause_or_default(&mut sig.generics.where_clause)
198+
.predicates
199+
.push(parse_quote_spanned!(span=> #param_name: 'async_trait + #bounds));
200+
} else {
201+
param.bounds.push(parse_quote!('async_trait));
202+
}
199203
}
200204
GenericParam::Lifetime(param) => {
201205
let param_name = &param.lifetime;
202206
let span = match param.colon_token.take() {
203207
Some(colon_token) => colon_token.span,
204208
None => param_name.span(),
205209
};
206-
let bounds = mem::take(&mut param.bounds);
207-
where_clause_or_default(&mut sig.generics.where_clause)
208-
.predicates
209-
.push(parse_quote_spanned!(span=> #param: 'async_trait + #bounds));
210+
if param.attrs.is_empty() {
211+
let bounds = mem::take(&mut param.bounds);
212+
where_clause_or_default(&mut sig.generics.where_clause)
213+
.predicates
214+
.push(parse_quote_spanned!(span=> #param: 'async_trait + #bounds));
215+
} else {
216+
param.bounds.push(parse_quote!('async_trait));
217+
}
210218
}
211219
GenericParam::Const(_) => {}
212220
}

tests/test.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1705,3 +1705,24 @@ pub mod issue283 {
17051705
}
17061706
}
17071707
}
1708+
1709+
// https://github.com/dtolnay/async-trait/issues/288
1710+
pub mod issue288 {
1711+
use async_trait::async_trait;
1712+
1713+
#[async_trait]
1714+
pub trait Trait {
1715+
async fn f<#[cfg(any())] T: Send>(#[cfg(any())] t: T);
1716+
async fn g<#[cfg(all())] T: Send>(#[cfg(all())] t: T);
1717+
}
1718+
1719+
pub struct Struct;
1720+
1721+
#[async_trait]
1722+
impl Trait for Struct {
1723+
async fn f<#[cfg(any())] T: Send>(#[cfg(any())] t: T) {}
1724+
async fn g<#[cfg(all())] T: Send>(#[cfg(all())] t: T) {
1725+
let _ = t;
1726+
}
1727+
}
1728+
}

0 commit comments

Comments
 (0)