diff --git a/src/expand.rs b/src/expand.rs index 85c39c6..ed0818e 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -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::{ @@ -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 = ¶m.ident; - let span = param.span(); + let param_name = ¶m.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 = ¶m.lifetime; - let span = param.span(); + let param_name = ¶m.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(_) => {} } diff --git a/tests/ui/consider-restricting.stderr b/tests/ui/consider-restricting.stderr index ee14180..86e3894 100644 --- a/tests/ui/consider-restricting.stderr +++ b/tests/ui/consider-restricting.stderr @@ -12,8 +12,8 @@ note: captured value is not `Send` = note: required for the cast to the object type `dyn Future + Send` help: consider further restricting this bound | -16 | async fn publish(&self, url: T) {} - | +++++++++++++++++++ +16 | async fn publish(&self, url: T) {} + | +++++++++++++++++++ error: future cannot be sent between threads safely --> tests/ui/consider-restricting.rs:23:40