@@ -68,14 +68,15 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
68
68
use util:: nodemap:: { FnvHashMap } ;
69
69
70
70
use arena:: TypedArena ;
71
- use std:: borrow:: BorrowFrom ;
71
+ use std:: borrow:: { BorrowFrom , Cow } ;
72
72
use std:: cell:: { Cell , RefCell } ;
73
73
use std:: cmp:: { self , Ordering } ;
74
74
use std:: fmt:: { self , Show } ;
75
75
use std:: hash:: { Hash , Writer , SipHasher , Hasher } ;
76
76
use std:: mem;
77
77
use std:: ops;
78
78
use std:: rc:: Rc ;
79
+ use std:: vec:: CowVec ;
79
80
use collections:: enum_set:: { EnumSet , CLike } ;
80
81
use std:: collections:: { HashMap , HashSet } ;
81
82
use syntax:: abi;
@@ -5555,35 +5556,20 @@ pub fn predicates<'tcx>(
5555
5556
vec
5556
5557
}
5557
5558
5558
- /// Iterate over attributes of a definition.
5559
- // (This should really be an iterator.)
5560
- pub fn each_attr < F > ( tcx : & ctxt , did : DefId , mut f : F ) -> bool where
5561
- F : FnMut ( & ast:: Attribute ) -> bool ,
5562
- {
5559
+ /// Get the attributes of a definition.
5560
+ pub fn get_attrs < ' tcx > ( tcx : & ' tcx ctxt , did : DefId )
5561
+ -> CowVec < ' tcx , ast:: Attribute > {
5563
5562
if is_local ( did) {
5564
5563
let item = tcx. map . expect_item ( did. node ) ;
5565
- item. attrs . iter ( ) . all ( |attr| f ( attr ) )
5564
+ Cow :: Borrowed ( & item. attrs [ ] )
5566
5565
} else {
5567
- info ! ( "getting foreign attrs" ) ;
5568
- let attrs = csearch:: get_item_attrs ( & tcx. sess . cstore , did) ;
5569
- let cont = attrs. iter ( ) . all ( |attr| f ( attr) ) ;
5570
- info ! ( "done" ) ;
5571
- cont
5566
+ Cow :: Owned ( csearch:: get_item_attrs ( & tcx. sess . cstore , did) )
5572
5567
}
5573
5568
}
5574
5569
5575
5570
/// Determine whether an item is annotated with an attribute
5576
5571
pub fn has_attr ( tcx : & ctxt , did : DefId , attr : & str ) -> bool {
5577
- let mut found = false ;
5578
- each_attr ( tcx, did, |item| {
5579
- if item. check_name ( attr) {
5580
- found = true ;
5581
- false
5582
- } else {
5583
- true
5584
- }
5585
- } ) ;
5586
- found
5572
+ get_attrs ( tcx, did) . iter ( ) . any ( |item| item. check_name ( attr) )
5587
5573
}
5588
5574
5589
5575
/// Determine whether an item is annotated with `#[repr(packed)]`
@@ -5600,13 +5586,9 @@ pub fn lookup_simd(tcx: &ctxt, did: DefId) -> bool {
5600
5586
pub fn lookup_repr_hints ( tcx : & ctxt , did : DefId ) -> Rc < Vec < attr:: ReprAttr > > {
5601
5587
memoized ( & tcx. repr_hint_cache , did, |did : DefId | {
5602
5588
Rc :: new ( if did. krate == LOCAL_CRATE {
5603
- let mut acc = Vec :: new ( ) ;
5604
- ty:: each_attr ( tcx, did, |meta| {
5605
- acc. extend ( attr:: find_repr_attrs ( tcx. sess . diagnostic ( ) ,
5606
- meta) . into_iter ( ) ) ;
5607
- true
5608
- } ) ;
5609
- acc
5589
+ get_attrs ( tcx, did) . iter ( ) . flat_map ( |meta| {
5590
+ attr:: find_repr_attrs ( tcx. sess . diagnostic ( ) , meta) . into_iter ( )
5591
+ } ) . collect ( )
5610
5592
} else {
5611
5593
csearch:: get_repr_attrs ( & tcx. sess . cstore , did)
5612
5594
} )
0 commit comments