@@ -457,35 +457,32 @@ impl<'ast> Map<'ast> {
457
457
}
458
458
}
459
459
460
- /// Given a node ID and a closure, apply the closure to the array
461
- /// of attributes associated with the AST corresponding to the Node ID
462
- pub fn with_attrs < T , F > ( & self , id : NodeId , f : F ) -> T where
463
- F : FnOnce ( Option < & [ Attribute ] > ) -> T ,
464
- {
465
- let attrs = match self . get ( id) {
466
- NodeItem ( i) => Some ( & i. attrs [ ..] ) ,
467
- NodeForeignItem ( fi) => Some ( & fi. attrs [ ..] ) ,
468
- NodeTraitItem ( ref tm) => match * * tm {
460
+ /// Given a node ID, get a list of of attributes associated with the AST
461
+ /// corresponding to the Node ID
462
+ pub fn attrs ( & self , id : NodeId ) -> & [ Attribute ] {
463
+ let attrs = match self . find ( id) {
464
+ Some ( NodeItem ( i) ) => Some ( & i. attrs [ ..] ) ,
465
+ Some ( NodeForeignItem ( fi) ) => Some ( & fi. attrs [ ..] ) ,
466
+ Some ( NodeTraitItem ( ref tm) ) => match * * tm {
469
467
RequiredMethod ( ref type_m) => Some ( & type_m. attrs [ ..] ) ,
470
468
ProvidedMethod ( ref m) => Some ( & m. attrs [ ..] ) ,
471
469
TypeTraitItem ( ref typ) => Some ( & typ. attrs [ ..] ) ,
472
470
} ,
473
- NodeImplItem ( ref ii) => {
471
+ Some ( NodeImplItem ( ref ii) ) => {
474
472
match * * ii {
475
473
MethodImplItem ( ref m) => Some ( & m. attrs [ ..] ) ,
476
474
TypeImplItem ( ref t) => Some ( & t. attrs [ ..] ) ,
477
475
}
478
476
}
479
- NodeVariant ( ref v) => Some ( & v. node . attrs [ ..] ) ,
477
+ Some ( NodeVariant ( ref v) ) => Some ( & v. node . attrs [ ..] ) ,
480
478
// unit/tuple structs take the attributes straight from
481
479
// the struct definition.
482
- // FIXME(eddyb) make this work again (requires access to the map).
483
- NodeStructCtor ( _) => {
484
- return self . with_attrs ( self . get_parent ( id) , f) ;
480
+ Some ( NodeStructCtor ( _) ) => {
481
+ return self . attrs ( self . get_parent ( id) ) ;
485
482
}
486
483
_ => None
487
484
} ;
488
- f ( attrs)
485
+ attrs. unwrap_or ( & [ ] )
489
486
}
490
487
491
488
/// Returns an iterator that yields the node id's with paths that
0 commit comments