@@ -179,12 +179,13 @@ impl Program {
179
179
} ,
180
180
_ => panic ! ( "unsupported self type in impl" ) ,
181
181
} ;
182
- for mut item in item. items . iter_mut ( ) {
183
- self . push_impl_item ( name, & mut item) ;
182
+ for item in item. items . iter_mut ( ) {
183
+ self . push_impl_item ( name, item) ;
184
184
}
185
185
}
186
186
187
187
fn push_impl_item ( & mut self , class : syn:: Ident , item : & mut syn:: ImplItem ) {
188
+ replace_self ( class, item) ;
188
189
let method = match item {
189
190
syn:: ImplItem :: Const ( _) => panic ! ( "const definitions aren't supported" ) ,
190
191
syn:: ImplItem :: Type ( _) => panic ! ( "type definitions in impls aren't supported" ) ,
@@ -458,7 +459,7 @@ impl Function {
458
459
459
460
pub fn from_decl (
460
461
name : syn:: Ident ,
461
- decl : Box < syn:: FnDecl > ,
462
+ mut decl : Box < syn:: FnDecl > ,
462
463
attrs : Vec < syn:: Attribute > ,
463
464
opts : BindgenAttrs ,
464
465
vis : syn:: Visibility ,
@@ -471,7 +472,7 @@ impl Function {
471
472
panic ! ( "can't bindgen functions with lifetime or type parameters" )
472
473
}
473
474
474
- assert_no_lifetimes ( & decl) ;
475
+ assert_no_lifetimes ( & mut decl) ;
475
476
476
477
let mut mutable = None ;
477
478
let arguments = decl. inputs
@@ -928,15 +929,29 @@ fn term<'a>(cursor: syn::buffer::Cursor<'a>, name: &str) -> syn::synom::PResult<
928
929
syn:: parse_error ( )
929
930
}
930
931
931
- fn assert_no_lifetimes ( decl : & syn:: FnDecl ) {
932
+ fn assert_no_lifetimes ( decl : & mut syn:: FnDecl ) {
932
933
struct Walk ;
933
934
934
- impl < ' ast > syn:: visit :: Visit < ' ast > for Walk {
935
- fn visit_lifetime ( & mut self , _i : & ' ast syn:: Lifetime ) {
935
+ impl < ' ast > syn:: visit_mut :: VisitMut for Walk {
936
+ fn visit_lifetime_mut ( & mut self , _i : & mut syn:: Lifetime ) {
936
937
panic ! ( "it is currently not sound to use lifetimes in function \
937
938
signatures") ;
938
939
}
939
940
}
940
941
941
- syn:: visit:: Visit :: visit_fn_decl ( & mut Walk , decl) ;
942
+ syn:: visit_mut:: VisitMut :: visit_fn_decl_mut ( & mut Walk , decl) ;
943
+ }
944
+
945
+ fn replace_self ( name : syn:: Ident , item : & mut syn:: ImplItem ) {
946
+ struct Walk ( syn:: Ident ) ;
947
+
948
+ impl syn:: visit_mut:: VisitMut for Walk {
949
+ fn visit_ident_mut ( & mut self , i : & mut syn:: Ident ) {
950
+ if i. as_ref ( ) == "Self" {
951
+ * i = self . 0 ;
952
+ }
953
+ }
954
+ }
955
+
956
+ syn:: visit_mut:: VisitMut :: visit_impl_item_mut ( & mut Walk ( name) , item) ;
942
957
}
0 commit comments