@@ -70,6 +70,8 @@ impl_macro_generable! {
70
70
P <ast:: Ty >: "type" , . make_ty, . fold_ty, |span| DummyResult :: raw_ty( span) ;
71
71
SmallVector <ast:: ImplItem >:
72
72
"impl item" , . make_impl_items, lift . fold_impl_item, |_span| SmallVector :: zero( ) ;
73
+ SmallVector <ast:: TraitItem >:
74
+ "trait item" , . make_trait_items, lift . fold_trait_item, |_span| SmallVector :: zero( ) ;
73
75
SmallVector <P <ast:: Item >>:
74
76
"item" , . make_items, lift . fold_item, |_span| SmallVector :: zero( ) ;
75
77
SmallVector <ast:: Stmt >:
@@ -760,25 +762,10 @@ fn expand_annotatable(a: Annotatable,
760
762
_ => noop_fold_item ( it, fld) ,
761
763
} . into_iter ( ) . map ( |i| Annotatable :: Item ( i) ) . collect ( ) ,
762
764
763
- Annotatable :: TraitItem ( it) => match it. node {
764
- ast:: TraitItemKind :: Method ( _, Some ( _) ) => {
765
- let ti = it. unwrap ( ) ;
766
- SmallVector :: one ( ast:: TraitItem {
767
- id : ti. id ,
768
- ident : ti. ident ,
769
- attrs : ti. attrs ,
770
- node : match ti. node {
771
- ast:: TraitItemKind :: Method ( sig, Some ( body) ) => {
772
- let ( sig, body) = expand_and_rename_method ( sig, body, fld) ;
773
- ast:: TraitItemKind :: Method ( sig, Some ( body) )
774
- }
775
- _ => unreachable ! ( )
776
- } ,
777
- span : ti. span ,
778
- } )
779
- }
780
- _ => fold:: noop_fold_trait_item ( it. unwrap ( ) , fld)
781
- } . into_iter ( ) . map ( |ti| Annotatable :: TraitItem ( P ( ti) ) ) . collect ( ) ,
765
+ Annotatable :: TraitItem ( it) => {
766
+ expand_trait_item ( it. unwrap ( ) , fld) . into_iter ( ) .
767
+ map ( |it| Annotatable :: TraitItem ( P ( it) ) ) . collect ( )
768
+ }
782
769
783
770
Annotatable :: ImplItem ( ii) => {
784
771
expand_impl_item ( ii. unwrap ( ) , fld) . into_iter ( ) .
@@ -934,6 +921,31 @@ fn expand_impl_item(ii: ast::ImplItem, fld: &mut MacroExpander)
934
921
}
935
922
}
936
923
924
+ fn expand_trait_item ( ti : ast:: TraitItem , fld : & mut MacroExpander )
925
+ -> SmallVector < ast:: TraitItem > {
926
+ match ti. node {
927
+ ast:: TraitItemKind :: Method ( _, Some ( _) ) => {
928
+ SmallVector :: one ( ast:: TraitItem {
929
+ id : ti. id ,
930
+ ident : ti. ident ,
931
+ attrs : ti. attrs ,
932
+ node : match ti. node {
933
+ ast:: TraitItemKind :: Method ( sig, Some ( body) ) => {
934
+ let ( sig, body) = expand_and_rename_method ( sig, body, fld) ;
935
+ ast:: TraitItemKind :: Method ( sig, Some ( body) )
936
+ }
937
+ _ => unreachable ! ( )
938
+ } ,
939
+ span : ti. span ,
940
+ } )
941
+ }
942
+ ast:: TraitItemKind :: Macro ( mac) => {
943
+ expand_mac_invoc ( mac, None , ti. attrs , ti. span , fld)
944
+ }
945
+ _ => fold:: noop_fold_trait_item ( ti, fld)
946
+ }
947
+ }
948
+
937
949
/// Given a fn_decl and a block and a MacroExpander, expand the fn_decl, then use the
938
950
/// PatIdents in its arguments to perform renaming in the FnDecl and
939
951
/// the block, returning both the new FnDecl and the new Block.
0 commit comments