Skip to content

Commit 46c3023

Browse files
committed
Move bounds from generic param list to where-clause after 'async_trait bound
1 parent cbf9669 commit 46c3023

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/expand.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::receiver::{has_self_in_block, has_self_in_sig, mut_pat, ReplaceSelf};
44
use proc_macro2::TokenStream;
55
use quote::{format_ident, quote, quote_spanned, ToTokens};
66
use std::collections::BTreeSet as Set;
7+
use std::mem;
78
use syn::punctuated::Punctuated;
89
use syn::visit_mut::{self, VisitMut};
910
use syn::{
@@ -179,21 +180,29 @@ fn transform_sig(
179180
}
180181
}
181182

182-
for param in &sig.generics.params {
183+
for param in &mut sig.generics.params {
183184
match param {
184185
GenericParam::Type(param) => {
185-
let param = &param.ident;
186-
let span = param.span();
186+
let param_name = &param.ident;
187+
let span = match param.colon_token.take() {
188+
Some(colon_token) => colon_token.span,
189+
None => param_name.span(),
190+
};
191+
let bounds = mem::replace(&mut param.bounds, Punctuated::new());
187192
where_clause_or_default(&mut sig.generics.where_clause)
188193
.predicates
189-
.push(parse_quote_spanned!(span=> #param: 'async_trait));
194+
.push(parse_quote_spanned!(span=> #param_name: 'async_trait + #bounds));
190195
}
191196
GenericParam::Lifetime(param) => {
192-
let param = &param.lifetime;
193-
let span = param.span();
197+
let param_name = &param.lifetime;
198+
let span = match param.colon_token.take() {
199+
Some(colon_token) => colon_token.span,
200+
None => param_name.span(),
201+
};
202+
let bounds = mem::replace(&mut param.bounds, Punctuated::new());
194203
where_clause_or_default(&mut sig.generics.where_clause)
195204
.predicates
196-
.push(parse_quote_spanned!(span=> #param: 'async_trait));
205+
.push(parse_quote_spanned!(span=> #param: 'async_trait + #bounds));
197206
}
198207
GenericParam::Const(_) => {}
199208
}

tests/ui/consider-restricting.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ note: captured value is not `Send`
1212
= note: required for the cast to the object type `dyn Future<Output = ()> + Send`
1313
help: consider further restricting this bound
1414
|
15-
16 | async fn publish<T + std::marker::Send: IntoUrl>(&self, url: T) {}
16-
| +++++++++++++++++++
15+
16 | async fn publish<T: IntoUrl + std::marker::Send>(&self, url: T) {}
16+
| +++++++++++++++++++
1717

1818
error: future cannot be sent between threads safely
1919
--> tests/ui/consider-restricting.rs:23:40

0 commit comments

Comments
 (0)