44
55use proc_macro2:: TokenStream ;
66use quote:: ToTokens ;
7- use syn:: { FnArg , ImplItem , ItemImpl , ItemTrait , Pat , TraitItem , TraitItemMethod } ;
7+ use syn:: { FnArg , ImplItem , ItemImpl , ItemTrait , Pat , TraitItem , TraitItemFn } ;
88
99use crate :: implementation:: ContractType ;
1010
@@ -16,8 +16,8 @@ fn contract_method_impl_name(name: &str) -> String {
1616/// Modifies a trait item in a way that it includes contracts.
1717pub ( crate ) fn contract_trait_item_trait ( _attrs : TokenStream , mut trait_ : ItemTrait ) -> TokenStream {
1818 /// Just rename the method to have an internal, generated name.
19- fn create_method_rename ( method : & TraitItemMethod ) -> TraitItemMethod {
20- let mut m: TraitItemMethod = ( * method) . clone ( ) ;
19+ fn create_method_rename ( method : & TraitItemFn ) -> TraitItemFn {
20+ let mut m = method. clone ( ) ;
2121
2222 // rename method and modify attributes
2323 {
@@ -35,8 +35,8 @@ pub(crate) fn contract_trait_item_trait(_attrs: TokenStream, mut trait_: ItemTra
3535 new_attrs. extend (
3636 m. attrs
3737 . iter ( )
38- . filter ( |a | {
39- let name = a . path . segments . last ( ) . unwrap ( ) . ident . to_string ( ) ;
38+ . filter ( |attr | {
39+ let name = attr . path ( ) . segments . last ( ) . unwrap ( ) . ident . to_string ( ) ;
4040
4141 ContractType :: contract_type_and_mode ( & name) . is_none ( )
4242 } )
@@ -55,7 +55,7 @@ pub(crate) fn contract_trait_item_trait(_attrs: TokenStream, mut trait_: ItemTra
5555 /// includes contracts.
5656 ///
5757 /// This new function forwards the call to the actual implementation.
58- fn create_method_wrapper ( method : & TraitItemMethod ) -> TraitItemMethod {
58+ fn create_method_wrapper ( method : & TraitItemFn ) -> TraitItemFn {
5959 struct ArgInfo {
6060 call_toks : proc_macro2:: TokenStream ,
6161 }
@@ -92,7 +92,7 @@ pub(crate) fn contract_trait_item_trait(_attrs: TokenStream, mut trait_: ItemTra
9292 }
9393 }
9494
95- let mut m: TraitItemMethod = ( * method) . clone ( ) ;
95+ let mut m = method. clone ( ) ;
9696
9797 let argument_data = m
9898 . sig
@@ -138,7 +138,7 @@ pub(crate) fn contract_trait_item_trait(_attrs: TokenStream, mut trait_: ItemTra
138138 m. attrs
139139 . iter ( )
140140 . filter ( |a| {
141- let name = a. path . segments . last ( ) . unwrap ( ) . ident . to_string ( ) ;
141+ let name = a. path ( ) . segments . last ( ) . unwrap ( ) . ident . to_string ( ) ;
142142 // is doc?
143143 if name == "doc" {
144144 return true ;
@@ -168,11 +168,11 @@ pub(crate) fn contract_trait_item_trait(_attrs: TokenStream, mut trait_: ItemTra
168168 . items
169169 . iter ( )
170170 . filter_map ( |item| {
171- if let TraitItem :: Method ( m) = item {
171+ if let TraitItem :: Fn ( m) = item {
172172 let rename = create_method_rename ( m) ;
173173 let wrapper = create_method_wrapper ( m) ;
174174
175- Some ( vec ! [ TraitItem :: Method ( rename) , TraitItem :: Method ( wrapper) ] )
175+ Some ( vec ! [ TraitItem :: Fn ( rename) , TraitItem :: Fn ( wrapper) ] )
176176 } else {
177177 None
178178 }
@@ -183,7 +183,7 @@ pub(crate) fn contract_trait_item_trait(_attrs: TokenStream, mut trait_: ItemTra
183183 // remove all previous methods
184184 trait_
185185 . items
186- . retain ( |item| !matches ! ( item, TraitItem :: Method ( _) ) ) ;
186+ . retain ( |item| !matches ! ( item, TraitItem :: Fn ( _) ) ) ;
187187
188188 // add back new methods
189189 trait_. items . extend ( funcs) ;
@@ -198,7 +198,7 @@ pub(crate) fn contract_trait_item_impl(_attrs: TokenStream, impl_: ItemImpl) ->
198198 let mut impl_: ItemImpl = impl_;
199199
200200 impl_. items . iter_mut ( ) . for_each ( |it| {
201- if let ImplItem :: Method ( method) = it {
201+ if let ImplItem :: Fn ( method) = it {
202202 let new_name = contract_method_impl_name ( & method. sig . ident . to_string ( ) ) ;
203203 let new_ident = syn:: Ident :: new ( & new_name, method. sig . ident . span ( ) ) ;
204204
0 commit comments