@@ -540,22 +540,32 @@ pub fn write_method_params<W: std::io::Write>(w: &mut W, sig: &syn::Signature, t
540
540
let mut first_arg = true ;
541
541
let mut num_unused = 0 ;
542
542
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
+ } ;
543
556
match inp {
544
557
syn:: FnArg :: Receiver ( recv) => {
545
558
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 ( ) ) ;
557
560
} ,
558
561
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
+
559
569
if types. skip_arg ( & * arg. ty , generics) { continue ; }
560
570
if !arg. attrs . is_empty ( ) { unimplemented ! ( ) ; }
561
571
// 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
606
616
match inp {
607
617
syn:: FnArg :: Receiver ( _) => { } ,
608
618
syn:: FnArg :: Typed ( arg) => {
619
+ if let syn:: Pat :: Ident ( id) = & * arg. pat {
620
+ if format ! ( "{}" , id. ident) == "self" {
621
+ continue ;
622
+ }
623
+ }
624
+
609
625
if types. skip_arg ( & * arg. ty , generics) { continue ; }
610
626
if !arg. attrs . is_empty ( ) { unimplemented ! ( ) ; }
611
627
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
666
682
}
667
683
} ,
668
684
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
+
669
696
if types. skip_arg ( & * arg. ty , generics) {
670
697
if !to_c {
671
698
if !first_arg {
0 commit comments