@@ -806,25 +806,34 @@ impl<'hir> Map<'hir> {
806
806
/// Given a node ID, gets a list of attributes associated with the AST
807
807
/// corresponding to the node-ID.
808
808
pub fn attrs ( & self , id : HirId ) -> & ' hir [ ast:: Attribute ] {
809
- let attrs = match self . find_entry ( id) . map ( |entry| entry. node ) {
810
- Some ( Node :: Param ( a) ) => Some ( & a. attrs [ ..] ) ,
811
- Some ( Node :: Local ( l) ) => Some ( & l. attrs [ ..] ) ,
812
- Some ( Node :: Item ( i) ) => Some ( & i. attrs [ ..] ) ,
813
- Some ( Node :: ForeignItem ( fi) ) => Some ( & fi. attrs [ ..] ) ,
814
- Some ( Node :: TraitItem ( ref ti) ) => Some ( & ti. attrs [ ..] ) ,
815
- Some ( Node :: ImplItem ( ref ii) ) => Some ( & ii. attrs [ ..] ) ,
816
- Some ( Node :: Variant ( ref v) ) => Some ( & v. attrs [ ..] ) ,
817
- Some ( Node :: Field ( ref f) ) => Some ( & f. attrs [ ..] ) ,
818
- Some ( Node :: Expr ( ref e) ) => Some ( & * e. attrs ) ,
819
- Some ( Node :: Stmt ( ref s) ) => Some ( s. kind . attrs ( |id| self . item ( id. id ) ) ) ,
820
- Some ( Node :: Arm ( ref a) ) => Some ( & * a. attrs ) ,
821
- Some ( Node :: GenericParam ( param) ) => Some ( & param. attrs [ ..] ) ,
809
+ let attrs = self . find_entry ( id) . map ( |entry| match entry. node {
810
+ Node :: Param ( a) => & a. attrs [ ..] ,
811
+ Node :: Local ( l) => & l. attrs [ ..] ,
812
+ Node :: Item ( i) => & i. attrs [ ..] ,
813
+ Node :: ForeignItem ( fi) => & fi. attrs [ ..] ,
814
+ Node :: TraitItem ( ref ti) => & ti. attrs [ ..] ,
815
+ Node :: ImplItem ( ref ii) => & ii. attrs [ ..] ,
816
+ Node :: Variant ( ref v) => & v. attrs [ ..] ,
817
+ Node :: Field ( ref f) => & f. attrs [ ..] ,
818
+ Node :: Expr ( ref e) => & * e. attrs ,
819
+ Node :: Stmt ( ref s) => s. kind . attrs ( |id| self . item ( id. id ) ) ,
820
+ Node :: Arm ( ref a) => & * a. attrs ,
821
+ Node :: GenericParam ( param) => & param. attrs [ ..] ,
822
822
// Unit/tuple structs/variants take the attributes straight from
823
823
// the struct/variant definition.
824
- Some ( Node :: Ctor ( ..) ) => return self . attrs ( self . get_parent_item ( id) ) ,
825
- Some ( Node :: Crate ( item) ) => Some ( & item. attrs [ ..] ) ,
826
- _ => None ,
827
- } ;
824
+ Node :: Ctor ( ..) => self . attrs ( self . get_parent_item ( id) ) ,
825
+ Node :: Crate ( item) => & item. attrs [ ..] ,
826
+ Node :: MacroDef ( def) => def. attrs ,
827
+ Node :: AnonConst ( ..)
828
+ | Node :: PathSegment ( ..)
829
+ | Node :: Ty ( ..)
830
+ | Node :: Pat ( ..)
831
+ | Node :: Binding ( ..)
832
+ | Node :: TraitRef ( ..)
833
+ | Node :: Block ( ..)
834
+ | Node :: Lifetime ( ..)
835
+ | Node :: Visibility ( ..) => & [ ] ,
836
+ } ) ;
828
837
attrs. unwrap_or ( & [ ] )
829
838
}
830
839
0 commit comments