@@ -540,22 +540,32 @@ pub fn write_method_params<W: std::io::Write>(w: &mut W, sig: &syn::Signature, t
540540 let mut first_arg = true ;
541541 let mut num_unused = 0 ;
542542 for inp in sig. inputs . iter ( ) {
543+ let mut handle_self = |is_ref : bool , is_mut : bool | {
544+ write ! ( w, "{}this_arg: {}{}" , if !is_ref { "mut " } else { "" } ,
545+ if is_ref {
546+ match ( self_ptr, is_mut) {
547+ ( true , true ) => "*mut " ,
548+ ( true , false ) => "*const " ,
549+ ( false , true ) => "&mut " ,
550+ ( false , false ) => "&" ,
551+ }
552+ } else { "" } , this_param) . unwrap ( ) ;
553+ assert ! ( first_arg) ;
554+ first_arg = false ;
555+ } ;
543556 match inp {
544557 syn:: FnArg :: Receiver ( recv) => {
545558 if !recv. attrs . is_empty ( ) { unimplemented ! ( ) ; }
546- write ! ( w, "{}this_arg: {}{}" , if recv. reference. is_none( ) { "mut " } else { "" } ,
547- if recv. reference. is_some( ) {
548- match ( self_ptr, recv. mutability. is_some( ) ) {
549- ( true , true ) => "*mut " ,
550- ( true , false ) => "*const " ,
551- ( false , true ) => "&mut " ,
552- ( false , false ) => "&" ,
553- }
554- } else { "" } , this_param) . unwrap ( ) ;
555- assert ! ( first_arg) ;
556- first_arg = false ;
559+ handle_self ( recv. reference . is_some ( ) , recv. mutability . is_some ( ) ) ;
557560 } ,
558561 syn:: FnArg :: Typed ( arg) => {
562+ if let syn:: Pat :: Ident ( id) = & * arg. pat {
563+ if format ! ( "{}" , id. ident) == "self" {
564+ handle_self ( id. by_ref . is_some ( ) , id. mutability . is_some ( ) ) ;
565+ continue ;
566+ }
567+ }
568+
559569 if types. skip_arg ( & * arg. ty , generics) { continue ; }
560570 if !arg. attrs . is_empty ( ) { unimplemented ! ( ) ; }
561571 // First get the c type so that we can check if it ends up being a reference:
@@ -606,6 +616,12 @@ pub fn write_method_var_decl_body<W: std::io::Write>(w: &mut W, sig: &syn::Signa
606616 match inp {
607617 syn:: FnArg :: Receiver ( _) => { } ,
608618 syn:: FnArg :: Typed ( arg) => {
619+ if let syn:: Pat :: Ident ( id) = & * arg. pat {
620+ if format ! ( "{}" , id. ident) == "self" {
621+ continue ;
622+ }
623+ }
624+
609625 if types. skip_arg ( & * arg. ty , generics) { continue ; }
610626 if !arg. attrs . is_empty ( ) { unimplemented ! ( ) ; }
611627 macro_rules! write_new_var {
@@ -666,6 +682,17 @@ pub fn write_method_call_params<W: std::io::Write>(w: &mut W, sig: &syn::Signatu
666682 }
667683 } ,
668684 syn:: FnArg :: Typed ( arg) => {
685+ if let syn:: Pat :: Ident ( id) = & * arg. pat {
686+ if format ! ( "{}" , id. ident) == "self" {
687+ if to_c {
688+ if id. by_ref . is_none ( ) && !matches ! ( & * arg. ty, syn:: Type :: Reference ( _) ) { unimplemented ! ( ) ; }
689+ write ! ( w, "self.this_arg" ) . unwrap ( ) ;
690+ first_arg = false ;
691+ }
692+ continue ;
693+ }
694+ }
695+
669696 if types. skip_arg ( & * arg. ty , generics) {
670697 if !to_c {
671698 if !first_arg {
0 commit comments