@@ -18,7 +18,7 @@ use ast;
18
18
use ast:: { AttrId , Attribute , Name } ;
19
19
use ast:: { MetaItem , MetaItemKind , NestedMetaItem , NestedMetaItemKind } ;
20
20
use ast:: { Lit , Expr , Item , Local , Stmt , StmtKind } ;
21
- use codemap:: { spanned, dummy_spanned, mk_sp} ;
21
+ use codemap:: { Spanned , spanned, dummy_spanned, mk_sp} ;
22
22
use syntax_pos:: { Span , BytePos , DUMMY_SP } ;
23
23
use errors:: Handler ;
24
24
use feature_gate:: { Features , GatedCfg } ;
@@ -959,6 +959,13 @@ pub trait HasAttrs: Sized {
959
959
fn map_attrs < F : FnOnce ( Vec < ast:: Attribute > ) -> Vec < ast:: Attribute > > ( self , f : F ) -> Self ;
960
960
}
961
961
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
+
962
969
impl HasAttrs for Vec < Attribute > {
963
970
fn attrs ( & self ) -> & [ Attribute ] {
964
971
& self
@@ -1012,26 +1019,31 @@ impl HasAttrs for StmtKind {
1012
1019
}
1013
1020
}
1014
1021
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) ,* ) => { $(
1018
1031
impl HasAttrs for $ty {
1019
1032
fn attrs( & self ) -> & [ Attribute ] {
1020
- self $ ( . $field ) * . attrs( )
1033
+ & self . attrs
1021
1034
}
1022
1035
1023
1036
fn map_attrs<F >( mut self , f: F ) -> Self
1024
1037
where F : FnOnce ( Vec <Attribute >) -> Vec <Attribute >,
1025
1038
{
1026
- self $ ( . $field ) * = self $ ( . $field ) * . map_attrs( f) ;
1039
+ self . attrs = self . attrs . map_attrs( f) ;
1027
1040
self
1028
1041
}
1029
1042
}
1030
1043
) * }
1031
1044
}
1032
1045
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_
1035
1049
}
1036
-
1037
- derive_has_attrs_from_field ! { Stmt : . node, ast:: Variant : . node. attrs }
0 commit comments