@@ -7,9 +7,9 @@ use std::mem;
7
7
use syn:: punctuated:: Punctuated ;
8
8
use syn:: visit_mut:: VisitMut ;
9
9
use syn:: {
10
- parse_quote, ArgCaptured , ArgSelfRef , Block , FnArg , GenericParam , Generics , Ident , ImplItem ,
11
- Lifetime , MethodSig , Pat , PatIdent , Path , ReturnType , Token , TraitItem , Type , TypeParam ,
12
- TypeParamBound , WhereClause ,
10
+ parse_quote, ArgCaptured , ArgSelf , ArgSelfRef , Block , FnArg , GenericParam , Generics , Ident ,
11
+ ImplItem , Lifetime , MethodSig , Pat , PatIdent , Path , ReturnType , Token , TraitItem , Type ,
12
+ TypeParam , TypeParamBound , WhereClause ,
13
13
} ;
14
14
15
15
impl ToTokens for Item {
@@ -256,44 +256,53 @@ fn transform_block(context: Context, sig: &mut MethodSig, block: &mut Block, has
256
256
let mut self_bound = None :: < TypeParamBound > ;
257
257
match standalone. decl . inputs . iter_mut ( ) . next ( ) {
258
258
Some ( arg @ FnArg :: SelfRef ( _) ) => {
259
- let ( lifetime, mutability) = match arg {
259
+ let ( lifetime, mutability, self_token ) = match arg {
260
260
FnArg :: SelfRef ( ArgSelfRef {
261
261
lifetime,
262
262
mutability,
263
+ self_token,
263
264
..
264
- } ) => ( lifetime, mutability) ,
265
+ } ) => ( lifetime, mutability, self_token ) ,
265
266
_ => unreachable ! ( ) ,
266
267
} ;
268
+ let under_self = Ident :: new ( "_self" , self_token. span ) ;
267
269
match context {
268
270
Context :: Trait { .. } => {
269
271
self_bound = Some ( match mutability {
270
272
Some ( _) => parse_quote ! ( core:: marker:: Send ) ,
271
273
None => parse_quote ! ( core:: marker:: Sync ) ,
272
274
} ) ;
273
275
* arg = parse_quote ! {
274
- _self : & #lifetime #mutability AsyncTrait
276
+ #under_self : & #lifetime #mutability AsyncTrait
275
277
} ;
276
278
}
277
279
Context :: Impl { receiver, .. } => {
278
280
* arg = parse_quote ! {
279
- _self : & #lifetime #mutability #receiver
281
+ #under_self : & #lifetime #mutability #receiver
280
282
} ;
281
283
}
282
284
}
283
285
}
284
- Some ( arg @ FnArg :: SelfValue ( _) ) => match context {
285
- Context :: Trait { .. } => {
286
- self_bound = Some ( parse_quote ! ( core:: marker:: Send ) ) ;
287
- * arg = parse_quote ! {
288
- _self: AsyncTrait
289
- } ;
290
- }
291
- Context :: Impl { receiver, .. } => {
292
- * arg = parse_quote ! {
293
- _self: #receiver
294
- } ;
286
+ Some ( arg @ FnArg :: SelfValue ( _) ) => {
287
+ let self_token = match arg {
288
+ FnArg :: SelfValue ( ArgSelf { self_token, .. } ) => self_token,
289
+ _ => unreachable ! ( ) ,
290
+ } ;
291
+ let under_self = Ident :: new ( "_self" , self_token. span ) ;
292
+ match context {
293
+ Context :: Trait { .. } => {
294
+ self_bound = Some ( parse_quote ! ( core:: marker:: Send ) ) ;
295
+ * arg = parse_quote ! {
296
+ #under_self: AsyncTrait
297
+ } ;
298
+ }
299
+ Context :: Impl { receiver, .. } => {
300
+ * arg = parse_quote ! {
301
+ #under_self: #receiver
302
+ } ;
303
+ }
295
304
}
296
- } ,
305
+ }
297
306
Some ( FnArg :: Captured ( ArgCaptured {
298
307
pat : Pat :: Ident ( arg) ,
299
308
..
0 commit comments