@@ -18,7 +18,7 @@ use ast;
1818use ast:: { AttrId , Attribute , Name } ;
1919use ast:: { MetaItem , MetaItemKind , NestedMetaItem , NestedMetaItemKind } ;
2020use ast:: { Lit , Expr , Item , Local , Stmt , StmtKind } ;
21- use codemap:: { spanned, dummy_spanned, mk_sp} ;
21+ use codemap:: { Spanned , spanned, dummy_spanned, mk_sp} ;
2222use syntax_pos:: { Span , BytePos , DUMMY_SP } ;
2323use errors:: Handler ;
2424use feature_gate:: { Features , GatedCfg } ;
@@ -959,6 +959,13 @@ pub trait HasAttrs: Sized {
959959 fn map_attrs < F : FnOnce ( Vec < ast:: Attribute > ) -> Vec < ast:: Attribute > > ( self , f : F ) -> Self ;
960960}
961961
962+ impl < T : HasAttrs > HasAttrs for Spanned < T > {
963+ fn attrs ( & self ) -> & [ ast:: Attribute ] { self . node . attrs ( ) }
964+ fn map_attrs < F : FnOnce ( Vec < ast:: Attribute > ) -> Vec < ast:: Attribute > > ( self , f : F ) -> Self {
965+ Spanned { node : self . node . map_attrs ( f) , span : self . span }
966+ }
967+ }
968+
962969impl HasAttrs for Vec < Attribute > {
963970 fn attrs ( & self ) -> & [ Attribute ] {
964971 & self
@@ -1012,26 +1019,31 @@ impl HasAttrs for StmtKind {
10121019 }
10131020}
10141021
1015- macro_rules! derive_has_attrs_from_field {
1016- ( $( $ty: path) ,* ) => { derive_has_attrs_from_field!( $( $ty: . attrs) ,* ) ; } ;
1017- ( $( $ty: path : $( . $field: ident) * ) ,* ) => { $(
1022+ impl HasAttrs for Stmt {
1023+ fn attrs ( & self ) -> & [ ast:: Attribute ] { self . node . attrs ( ) }
1024+ fn map_attrs < F : FnOnce ( Vec < ast:: Attribute > ) -> Vec < ast:: Attribute > > ( self , f : F ) -> Self {
1025+ Stmt { id : self . id , node : self . node . map_attrs ( f) , span : self . span }
1026+ }
1027+ }
1028+
1029+ macro_rules! derive_has_attrs {
1030+ ( $( $ty: path) ,* ) => { $(
10181031 impl HasAttrs for $ty {
10191032 fn attrs( & self ) -> & [ Attribute ] {
1020- self $ ( . $field ) * . attrs( )
1033+ & self . attrs
10211034 }
10221035
10231036 fn map_attrs<F >( mut self , f: F ) -> Self
10241037 where F : FnOnce ( Vec <Attribute >) -> Vec <Attribute >,
10251038 {
1026- self $ ( . $field ) * = self $ ( . $field ) * . map_attrs( f) ;
1039+ self . attrs = self . attrs . map_attrs( f) ;
10271040 self
10281041 }
10291042 }
10301043 ) * }
10311044}
10321045
1033- derive_has_attrs_from_field ! {
1034- Item , Expr , Local , ast:: ForeignItem , ast:: StructField , ast:: ImplItem , ast:: TraitItem , ast:: Arm
1046+ derive_has_attrs ! {
1047+ Item , Expr , Local , ast:: ForeignItem , ast:: StructField , ast:: ImplItem , ast:: TraitItem , ast:: Arm ,
1048+ ast:: Field , ast:: FieldPat , ast:: Variant_
10351049}
1036-
1037- derive_has_attrs_from_field ! { Stmt : . node, ast:: Variant : . node. attrs }
0 commit comments