@@ -188,7 +188,7 @@ pub(crate) fn generate(
188188 result. extend (
189189 quote:: quote_spanned! { span=>
190190 if !( #exec_expr) {
191- log:: error!( #format_args) ;
191+ log:: error!( "{}" , #format_args) ;
192192 }
193193 }
194194 . into_iter ( ) ,
@@ -198,7 +198,7 @@ pub(crate) fn generate(
198198 if let Some ( assert_macro) = get_assert_macro ( ctype, mode, span) {
199199 result. extend (
200200 quote:: quote_spanned! { span=>
201- #assert_macro!( #exec_expr, #format_args) ;
201+ #assert_macro!( #exec_expr, "{}" , #format_args) ;
202202 }
203203 . into_iter ( ) ,
204204 ) ;
@@ -460,7 +460,21 @@ fn create_body_closure(func: &syn::ItemFn) -> TokenStream {
460460 }
461461
462462 closure_args. push ( receiver) ;
463- arg_names. push ( syn:: Ident :: new ( "self" , Span :: call_site ( ) ) ) ;
463+
464+ match & func. sig . inputs [ 0 ] {
465+ syn:: FnArg :: Receiver ( receiver) => {
466+ arg_names
467+ . push ( syn:: Ident :: new ( "self" , receiver. self_token . span ( ) ) ) ;
468+ }
469+ syn:: FnArg :: Typed ( pat) => {
470+ if let syn:: Pat :: Ident ( ident) = & * pat. pat {
471+ arg_names. push ( ident. ident . clone ( ) ) ;
472+ } else {
473+ // Non-trivial receiver pattern => do not capture
474+ closure_args. pop ( ) ;
475+ }
476+ }
477+ } ;
464478
465479 // Replace any references to `self` in the function body with references to `this`.
466480 syn:: visit_mut:: visit_block_mut (
@@ -482,8 +496,16 @@ fn create_body_closure(func: &syn::ItemFn) -> TokenStream {
482496 syn:: FnArg :: Typed ( syn:: PatType { pat, ty, .. } ) => {
483497 if !ty_contains_impl_trait ( ty) {
484498 if let syn:: Pat :: Ident ( ident) = & * * pat {
485- arg_names. push ( ident. ident . clone ( ) ) ;
486- closure_args. push ( arg. clone ( ) ) ;
499+ let ident_str = ident. ident . to_string ( ) ;
500+
501+ // Any function argument identifier starting with '_' signals
502+ // that the binding will not be used.
503+ if !ident_str. starts_with ( '_' )
504+ || ident_str. starts_with ( "__" )
505+ {
506+ arg_names. push ( ident. ident . clone ( ) ) ;
507+ closure_args. push ( arg. clone ( ) ) ;
508+ }
487509 }
488510 }
489511 }
0 commit comments