@@ -323,7 +323,7 @@ pub(crate) fn generate(
323
323
let block = & func. function . block ;
324
324
quote:: quote! { let ret = #block; }
325
325
} else {
326
- create_closure_body_and_adjust_signature ( & func. function )
326
+ create_body_closure ( & func. function )
327
327
} ;
328
328
329
329
//
@@ -389,18 +389,20 @@ fn ty_contains_impl_trait(ty: &syn::Type) -> bool {
389
389
vis. seen_impl_trait
390
390
}
391
391
392
- fn create_closure_body_and_adjust_signature ( func : & syn:: ItemFn ) -> TokenStream {
392
+ fn create_body_closure ( func : & syn:: ItemFn ) -> TokenStream {
393
393
let is_method = func. sig . receiver ( ) . is_some ( ) ;
394
394
395
395
// If the function has a receiver (e.g. `self`, `&mut self`, or `self: Box<Self>`) rename it
396
- // to `this__ ` within the closure
396
+ // to `this ` within the closure
397
397
398
398
let mut block = func. block . clone ( ) ;
399
399
let mut closure_args = vec ! [ ] ;
400
400
let mut arg_names = vec ! [ ] ;
401
401
402
402
if is_method {
403
- let this_ident = syn:: Ident :: new ( "this__" , Span :: call_site ( ) ) ;
403
+ // `mixed_site` makes the identifier hygienic so it won't collide with a local variable
404
+ // named `this`.
405
+ let this_ident = syn:: Ident :: new ( "this" , Span :: mixed_site ( ) ) ;
404
406
405
407
let mut receiver = func. sig . inputs [ 0 ] . clone ( ) ;
406
408
match receiver {
@@ -430,7 +432,7 @@ fn create_closure_body_and_adjust_signature(func: &syn::ItemFn) -> TokenStream {
430
432
None
431
433
} ;
432
434
433
- // this__ : [& [mut]] Self
435
+ // this : [& [mut]] Self
434
436
let new_rcv = syn:: PatType {
435
437
attrs : rcv. attrs . clone ( ) ,
436
438
pat : Box :: new ( syn:: Pat :: Ident ( syn:: PatIdent {
@@ -460,7 +462,7 @@ fn create_closure_body_and_adjust_signature(func: &syn::ItemFn) -> TokenStream {
460
462
closure_args. push ( receiver) ;
461
463
arg_names. push ( syn:: Ident :: new ( "self" , Span :: call_site ( ) ) ) ;
462
464
463
- // Replace any references to `self` in the function body with references to `this__ `.
465
+ // Replace any references to `self` in the function body with references to `this `.
464
466
syn:: visit_mut:: visit_block_mut (
465
467
& mut SelfReplacer {
466
468
replace_with : & this_ident,
@@ -469,8 +471,9 @@ fn create_closure_body_and_adjust_signature(func: &syn::ItemFn) -> TokenStream {
469
471
) ;
470
472
}
471
473
472
- // Replace any pattern matching in the function signature with placeholder identifiers.
473
- // Pattern matching gets done in the closure instead.
474
+ // Any function arguments of the form `ident: ty` become closure arguments and get passed
475
+ // explicitly. More complex ones, e.g. pattern matching like `(a, b): (u32, u32)`, are
476
+ // captured instead.
474
477
let args = func. sig . inputs . iter ( ) . skip ( if is_method { 1 } else { 0 } ) ;
475
478
for arg in args {
476
479
match arg {
0 commit comments