@@ -37,7 +37,7 @@ enum Context<'a> {
37
37
38
38
type Supertraits = Punctuated < TypeParamBound , Token ! [ +] > ;
39
39
40
- pub fn expand ( input : & mut Item ) {
40
+ pub fn expand ( input : & mut Item , is_local : bool ) {
41
41
match input {
42
42
Item :: Trait ( input) => {
43
43
let context = Context :: Trait {
@@ -49,10 +49,10 @@ pub fn expand(input: &mut Item) {
49
49
if let TraitItem :: Method ( method) = inner {
50
50
if method. sig . asyncness . is_some ( ) {
51
51
if let Some ( block) = & mut method. default {
52
- transform_block ( context, & method. sig , block) ;
52
+ transform_block ( context, & method. sig , block, is_local ) ;
53
53
}
54
54
let has_default = method. default . is_some ( ) ;
55
- transform_sig ( context, & mut method. sig , has_default) ;
55
+ transform_sig ( context, & mut method. sig , has_default, is_local ) ;
56
56
}
57
57
}
58
58
}
@@ -66,8 +66,8 @@ pub fn expand(input: &mut Item) {
66
66
for inner in & mut input. items {
67
67
if let ImplItem :: Method ( method) = inner {
68
68
if method. sig . asyncness . is_some ( ) {
69
- transform_block ( context, & method. sig , & mut method. block ) ;
70
- transform_sig ( context, & mut method. sig , false ) ;
69
+ transform_block ( context, & method. sig , & mut method. block , is_local ) ;
70
+ transform_sig ( context, & mut method. sig , false , is_local ) ;
71
71
}
72
72
}
73
73
}
@@ -88,7 +88,7 @@ pub fn expand(input: &mut Item) {
88
88
// 'life1: 'async_trait,
89
89
// T: 'async_trait,
90
90
// Self: Sync + 'async_trait;
91
- fn transform_sig ( context : Context , sig : & mut MethodSig , has_default : bool ) {
91
+ fn transform_sig ( context : Context , sig : & mut MethodSig , has_default : bool , is_local : bool ) {
92
92
sig. decl . fn_token . span = sig. asyncness . take ( ) . unwrap ( ) . span ;
93
93
94
94
let ret = match & sig. decl . output {
@@ -187,9 +187,15 @@ fn transform_sig(context: Context, sig: &mut MethodSig, has_default: bool) {
187
187
}
188
188
}
189
189
190
+ let bounds: Supertraits = if is_local {
191
+ parse_quote ! ( #lifetime)
192
+ } else {
193
+ parse_quote ! ( #lifetime + core:: marker:: Send )
194
+ } ;
195
+
190
196
sig. decl . output = parse_quote ! {
191
197
-> core:: pin:: Pin <Box <
192
- dyn core:: future:: Future <Output = #ret> + core :: marker :: Send + #lifetime
198
+ dyn core:: future:: Future <Output = #ret> + #bounds
193
199
>>
194
200
} ;
195
201
}
@@ -204,7 +210,7 @@ fn transform_sig(context: Context, sig: &mut MethodSig, has_default: bool) {
204
210
// _self + x
205
211
// }
206
212
// Pin::from(Box::new(async_trait_method::<T, Self>(self, x)))
207
- fn transform_block ( context : Context , sig : & MethodSig , block : & mut Block ) {
213
+ fn transform_block ( context : Context , sig : & MethodSig , block : & mut Block , is_local : bool ) {
208
214
let inner = Ident :: new ( & format ! ( "__{}" , sig. ident) , sig. ident . span ( ) ) ;
209
215
let args = sig
210
216
. decl
@@ -271,9 +277,15 @@ fn transform_block(context: Context, sig: &MethodSig, block: &mut Block) {
271
277
_self: & #lifetime #mutability AsyncTrait
272
278
} ;
273
279
let ( _, generics, _) = generics. split_for_impl ( ) ;
274
- standalone. decl . generics . params . push ( parse_quote ! {
275
- AsyncTrait : ?Sized + #name #generics + core:: marker:: #bound
276
- } ) ;
280
+ if is_local {
281
+ standalone. decl . generics . params . push ( parse_quote ! {
282
+ AsyncTrait : ?Sized + #name #generics
283
+ } ) ;
284
+ } else {
285
+ standalone. decl . generics . params . push ( parse_quote ! {
286
+ AsyncTrait : ?Sized + #name #generics + core:: marker:: #bound
287
+ } ) ;
288
+ }
277
289
types. push ( Ident :: new ( "Self" , Span :: call_site ( ) ) ) ;
278
290
}
279
291
Context :: Impl { receiver, .. } => {
0 commit comments