Skip to content

Commit

Permalink
Move bounds from generic param list to where-clause after 'async_trai…
Browse files Browse the repository at this point in the history
…t bound
  • Loading branch information
dtolnay committed Mar 25, 2022
1 parent cbf9669 commit 46c3023
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::receiver::{has_self_in_block, has_self_in_sig, mut_pat, ReplaceSelf};
use proc_macro2::TokenStream;
use quote::{format_ident, quote, quote_spanned, ToTokens};
use std::collections::BTreeSet as Set;
use std::mem;
use syn::punctuated::Punctuated;
use syn::visit_mut::{self, VisitMut};
use syn::{
Expand Down Expand Up @@ -179,21 +180,29 @@ fn transform_sig(
}
}

for param in &sig.generics.params {
for param in &mut sig.generics.params {
match param {
GenericParam::Type(param) => {
let param = &param.ident;
let span = param.span();
let param_name = &param.ident;
let span = match param.colon_token.take() {
Some(colon_token) => colon_token.span,
None => param_name.span(),
};
let bounds = mem::replace(&mut param.bounds, Punctuated::new());
where_clause_or_default(&mut sig.generics.where_clause)
.predicates
.push(parse_quote_spanned!(span=> #param: 'async_trait));
.push(parse_quote_spanned!(span=> #param_name: 'async_trait + #bounds));
}
GenericParam::Lifetime(param) => {
let param = &param.lifetime;
let span = param.span();
let param_name = &param.lifetime;
let span = match param.colon_token.take() {
Some(colon_token) => colon_token.span,
None => param_name.span(),
};
let bounds = mem::replace(&mut param.bounds, Punctuated::new());
where_clause_or_default(&mut sig.generics.where_clause)
.predicates
.push(parse_quote_spanned!(span=> #param: 'async_trait));
.push(parse_quote_spanned!(span=> #param: 'async_trait + #bounds));
}
GenericParam::Const(_) => {}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/consider-restricting.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ note: captured value is not `Send`
= note: required for the cast to the object type `dyn Future<Output = ()> + Send`
help: consider further restricting this bound
|
16 | async fn publish<T + std::marker::Send: IntoUrl>(&self, url: T) {}
| +++++++++++++++++++
16 | async fn publish<T: IntoUrl + std::marker::Send>(&self, url: T) {}
| +++++++++++++++++++

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

0 comments on commit 46c3023

Please sign in to comment.