fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec<DefId> {
    use hir::itemlikevisit;

    let mut traits = vec![];

    // Crate-local:

    struct Visitor<'a, 'tcx> {
        map: &'a hir_map::Map<'tcx>,
        traits: &'a mut Vec<DefId>,
    }

    impl<'v, 'a, 'tcx> itemlikevisit::ItemLikeVisitor<'v> for Visitor<'a, 'tcx> {
        fn visit_item(&mut self, i: &'v hir::Item<'v>) {
            match i.kind {
                hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => {
                    let def_id = self.map.local_def_id(i.hir_id);
                    self.traits.push(def_id.to_def_id());
                }
                _ => (),
            }
        }

        fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {}

        fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {}
    }

    tcx.hir().krate().visit_all_item_likes(&mut Visitor { map: &tcx.hir(), traits: &mut traits });

    // Cross-crate:

    let mut external_mods = FxHashSet::default();
    fn handle_external_res(
        tcx: TyCtxt<'_>,
        traits: &mut Vec<DefId>,
        external_mods: &mut FxHashSet<DefId>,
        res: Res,
    ) {
        match res {
            Res::Def(DefKind::Trait | DefKind::TraitAlias, def_id) => {
                traits.push(def_id);
            }
            Res::Def(DefKind::Mod, def_id) => {
                if !external_mods.insert(def_id) {
                    return;
                }
                for child in tcx.item_children(def_id).iter() {
                    handle_external_res(tcx, traits, external_mods, child.res)
                }
            }
            _ => {}
        }
    }
    for &cnum in tcx.crates().iter() {
        let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
        handle_external_res(tcx, &mut traits, &mut external_mods, Res::Def(DefKind::Mod, def_id));
    }

    traits
}
/// Computes all traits in this crate and any dependent crates.
Computes all traits in this crate and any dependent crates.
Computes all traits in this crate and any dependent crates .
fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec<DefId> {
    use hir::itemlikevisit;
    let mut traits = vec![];
    // Crate-local:
    struct Visitor<'a, 'tcx> {
        map: &'a hir_map::Map<'tcx>,
        traits: &'a mut Vec<DefId>,
    }
    impl<'v, 'a, 'tcx> itemlikevisit::ItemLikeVisitor<'v> for Visitor<'a, 'tcx> {
        fn visit_item(&mut self, i: &'v hir::Item<'v>) {
            match i.kind {
                hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => {
                    let def_id = self.map.local_def_id(i.hir_id);
                    self.traits.push(def_id.to_def_id());
                }
                _ => (),
            }
        }
        fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {}
        fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {}
    }
    tcx.hir().krate().visit_all_item_likes(&mut Visitor { map: &tcx.hir(), traits: &mut traits });
    // Cross-crate:
    let mut external_mods = FxHashSet::default();
    fn handle_external_res(
        tcx: TyCtxt<'_>,
        traits: &mut Vec<DefId>,
        external_mods: &mut FxHashSet<DefId>,
        res: Res,
    ) {
        match res {
            Res::Def(DefKind::Trait | DefKind::TraitAlias, def_id) => {
                traits.push(def_id);
            }
            Res::Def(DefKind::Mod, def_id) => {
                if !external_mods.insert(def_id) {
                    return;
                }
                for child in tcx.item_children(def_id).iter() {
                    handle_external_res(tcx, traits, external_mods, child.res)
                }
            }
            _ => {}
        }
    }
    for &cnum in tcx.crates().iter() {
        let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
        handle_external_res(tcx, &mut traits, &mut external_mods, Res::Def(DefKind::Mod, def_id));
    }
    traits
}
fn compute_all_traits ( tcx : TyCtxt < ' _ > ) -> Vec < DefId > { use hir :: itemlikevisit ; let mut traits = vec ! [ ] ; // Crate-local: struct Visitor < ' a , ' tcx > { map : & ' a hir_map :: Map < ' tcx > , traits : & ' a mut Vec < DefId > , } impl < ' v , ' a , ' tcx > itemlikevisit :: ItemLikeVisitor < ' v > for Visitor < ' a , ' tcx > { fn visit_item ( & mut self , i : & ' v hir :: Item < ' v > ) { match i . kind { hir :: ItemKind :: Trait ( .. ) | hir :: ItemKind :: TraitAlias ( .. ) => { let def_id = self . map . local_def_id ( i . hir_id ) ; self . traits . push ( def_id . to_def_id ( ) ) ; } _ => ( ) , } } fn visit_trait_item ( & mut self , _trait_item : & hir :: TraitItem < ' _ > ) { } fn visit_impl_item ( & mut self , _impl_item : & hir :: ImplItem < ' _ > ) { } } tcx . hir ( ) . krate ( ) . visit_all_item_likes ( & mut Visitor { map : & tcx . hir ( ) , traits : & mut traits } ) ; // Cross-crate: let mut external_mods = FxHashSet :: default ( ) ; fn handle_external_res ( tcx : TyCtxt < ' _ > , traits : & mut Vec < DefId > , external_mods : & mut FxHashSet < DefId > , res : Res , ) { match res { Res :: Def ( DefKind :: Trait | DefKind :: TraitAlias , def_id ) => { traits . push ( def_id ) ; } Res :: Def ( DefKind :: Mod , def_id ) => { if ! external_mods . insert ( def_id ) { return ; } for child in tcx . item_children ( def_id ) . iter ( ) { handle_external_res ( tcx , traits , external_mods , child . res ) } } _ => { } } } for & cnum in tcx . crates ( ) . iter ( ) { let def_id = DefId { krate : cnum , index : CRATE_DEF_INDEX } ; handle_external_res ( tcx , & mut traits , & mut external_mods , Res :: Def ( DefKind :: Mod , def_id ) ) ; } traits }
Computes all traits in this crate and any dependent crates.
Computes all traits in this crate and any dependent crates .
tcx
TyCtxt<'_>
tcx
TyCtxt<'_>