/// Retrieve all traits in this crate and any dependent crates.
Retrieve all traits in this crate and any dependent crates.
Retrieve all traits in this crate and any dependent crates .
pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> {
    if ccx.all_traits.borrow().is_none() {
        use rustc_front::visit;
        let mut traits = vec![];
        // Crate-local:
        //
        // meh.
        struct Visitor<'a> {
            traits: &'a mut AllTraitsVec,
        }
        impl<'v, 'a> visit::Visitor<'v> for Visitor<'a> {
            fn visit_item(&mut self, i: &'v hir::Item) {
                match i.node {
                    hir::ItemTrait(..) => {
                        self.traits.push(TraitInfo::new(DefId::local(i.id)));
                    }
                    _ => {}
                }
                visit::walk_item(self, i)
            }
        }
        visit::walk_crate(&mut Visitor {
            traits: &mut traits
        }, ccx.tcx.map.krate());
        // Cross-crate:
        fn handle_external_def(traits: &mut AllTraitsVec,
                               ccx: &CrateCtxt,
                               cstore: &cstore::CStore,
                               dl: decoder::DefLike) {
            match dl {
                decoder::DlDef(def::DefTrait(did)) => {
                    traits.push(TraitInfo::new(did));
                }
                decoder::DlDef(def::DefMod(did)) => {
                    csearch::each_child_of_item(cstore, did, |dl, _, _| {
                        handle_external_def(traits, ccx, cstore, dl)
                    })
                }
                _ => {}
            }
        }
        let cstore = &ccx.tcx.sess.cstore;
        cstore.iter_crate_data(|cnum, _| {
            csearch::each_top_level_item_of_crate(cstore, cnum, |dl, _, _| {
                handle_external_def(&mut traits, ccx, cstore, dl)
            })
        });
        *ccx.all_traits.borrow_mut() = Some(traits);
    }
    let borrow = ccx.all_traits.borrow();
    assert!(borrow.is_some());
    AllTraits {
        borrow: borrow,
        idx: 0
    }
}
pub fn all_traits < ' a > ( ccx : & ' a CrateCtxt ) -> AllTraits < ' a > { if ccx . all_traits . borrow ( ) . is_none ( ) { use rustc_front :: visit ; let mut traits = vec ! [ ] ; // Crate-local: // // meh. struct Visitor < ' a > { traits : & ' a mut AllTraitsVec , } impl < ' v , ' a > visit :: Visitor < ' v > for Visitor < ' a > { fn visit_item ( & mut self , i : & ' v hir :: Item ) { match i . node { hir :: ItemTrait ( .. ) => { self . traits . push ( TraitInfo :: new ( DefId :: local ( i . id ) ) ) ; } _ => { } } visit :: walk_item ( self , i ) } } visit :: walk_crate ( & mut Visitor { traits : & mut traits } , ccx . tcx . map . krate ( ) ) ; // Cross-crate: fn handle_external_def ( traits : & mut AllTraitsVec , ccx : & CrateCtxt , cstore : & cstore :: CStore , dl : decoder :: DefLike ) { match dl { decoder :: DlDef ( def :: DefTrait ( did ) ) => { traits . push ( TraitInfo :: new ( did ) ) ; } decoder :: DlDef ( def :: DefMod ( did ) ) => { csearch :: each_child_of_item ( cstore , did , | dl , _ , _ | { handle_external_def ( traits , ccx , cstore , dl ) } ) } _ => { } } } let cstore = & ccx . tcx . sess . cstore ; cstore . iter_crate_data ( | cnum , _ | { csearch :: each_top_level_item_of_crate ( cstore , cnum , | dl , _ , _ | { handle_external_def ( & mut traits , ccx , cstore , dl ) } ) } ) ; * ccx . all_traits . borrow_mut ( ) = Some ( traits ) ; } let borrow = ccx . all_traits . borrow ( ) ; assert ! ( borrow is_some ( ) ) ; AllTraits { borrow : borrow , idx : 0 } }
Retrieve all traits in this crate and any dependent crates.
Retrieve all traits in this crate and any dependent crates .
ccx
&'a CrateCtxt