@@ -68,14 +68,15 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
6868use util:: nodemap:: { FnvHashMap } ;
6969
7070use arena:: TypedArena ;
71- use std:: borrow:: BorrowFrom ;
71+ use std:: borrow:: { BorrowFrom , Cow } ;
7272use std:: cell:: { Cell , RefCell } ;
7373use std:: cmp:: { self , Ordering } ;
7474use std:: fmt:: { self , Show } ;
7575use std:: hash:: { Hash , Writer , SipHasher , Hasher } ;
7676use std:: mem;
7777use std:: ops;
7878use std:: rc:: Rc ;
79+ use std:: vec:: CowVec ;
7980use collections:: enum_set:: { EnumSet , CLike } ;
8081use std:: collections:: { HashMap , HashSet } ;
8182use syntax:: abi;
@@ -5555,35 +5556,20 @@ pub fn predicates<'tcx>(
55555556 vec
55565557}
55575558
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 > {
55635562 if is_local ( did) {
55645563 let item = tcx. map . expect_item ( did. node ) ;
5565- item. attrs . iter ( ) . all ( |attr| f ( attr ) )
5564+ Cow :: Borrowed ( & item. attrs [ ] )
55665565 } 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) )
55725567 }
55735568}
55745569
55755570/// Determine whether an item is annotated with an attribute
55765571pub 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) )
55875573}
55885574
55895575/// Determine whether an item is annotated with `#[repr(packed)]`
@@ -5600,13 +5586,9 @@ pub fn lookup_simd(tcx: &ctxt, did: DefId) -> bool {
56005586pub fn lookup_repr_hints ( tcx : & ctxt , did : DefId ) -> Rc < Vec < attr:: ReprAttr > > {
56015587 memoized ( & tcx. repr_hint_cache , did, |did : DefId | {
56025588 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 ( )
56105592 } else {
56115593 csearch:: get_repr_attrs ( & tcx. sess . cstore , did)
56125594 } )
0 commit comments