@@ -5,6 +5,7 @@ use proc_macro2::TokenStream;
5
5
use quote:: { format_ident, quote, quote_spanned, ToTokens } ;
6
6
use std:: collections:: BTreeSet as Set ;
7
7
use syn:: punctuated:: Punctuated ;
8
+ use syn:: spanned:: Spanned ;
8
9
use syn:: visit_mut:: { self , VisitMut } ;
9
10
use syn:: {
10
11
parse_quote, parse_quote_spanned, Attribute , Block , FnArg , GenericParam , Generics , Ident ,
@@ -186,18 +187,30 @@ fn transform_sig(
186
187
{
187
188
match param {
188
189
GenericParam :: Type ( param) => {
190
+ let span = if param. bounds . is_empty ( ) {
191
+ // This should use `Span::def_site()`, but that's not stable.
192
+ param. ident . span ( )
193
+ } else {
194
+ param. bounds . span ( )
195
+ } ;
189
196
let param = & param. ident ;
190
- let span = param . span ( ) ;
197
+ let life = quote_spanned ! ( span=> : ' async_trait ) ;
191
198
where_clause_or_default ( & mut sig. generics . where_clause )
192
199
. predicates
193
- . push ( parse_quote_spanned ! ( span=> #param: ' async_trait ) ) ;
200
+ . push ( parse_quote ! ( #param #life ) ) ;
194
201
}
195
202
GenericParam :: Lifetime ( param) => {
203
+ let span = if param. bounds . is_empty ( ) {
204
+ // This should use `Span::def_site()`, but that's not stable.
205
+ param. lifetime . span ( )
206
+ } else {
207
+ param. bounds . span ( )
208
+ } ;
196
209
let param = & param. lifetime ;
197
- let span = param . span ( ) ;
210
+ let life = quote_spanned ! ( span=> : ' async_trait ) ;
198
211
where_clause_or_default ( & mut sig. generics . where_clause )
199
212
. predicates
200
- . push ( parse_quote_spanned ! ( span=> #param: ' async_trait ) ) ;
213
+ . push ( parse_quote ! ( #param #life ) ) ;
201
214
}
202
215
GenericParam :: Const ( _) => { }
203
216
}
@@ -385,7 +398,6 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) {
385
398
}
386
399
387
400
fn positional_arg ( i : usize , pat : & Pat ) -> Ident {
388
- use syn:: spanned:: Spanned ;
389
401
format_ident ! ( "__arg{}" , i, span = pat. span( ) )
390
402
}
391
403
0 commit comments