fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F, sess: &Session)
        where F: FnMut(def::Export<hir::HirId>)
    {
        if let Some(proc_macros_ids) = self.root.proc_macro_data.map(|d| d.decode(self)) {
            /* If we are loading as a proc macro, we want to return the view of this crate
             * as a proc macro crate.
             */
            if id == CRATE_DEF_INDEX {
                for def_index in proc_macros_ids {
                    let raw_macro = self.raw_proc_macro(def_index);
                    let res = Res::Def(
                        DefKind::Macro(macro_kind(raw_macro)),
                        self.local_def_id(def_index),
                    );
                    let ident = Ident::from_str(raw_macro.name());
                    callback(def::Export {
                        ident: ident,
                        res: res,
                        vis: ty::Visibility::Public,
                        span: DUMMY_SP,
                    });
                }
            }
            return
        }

        // Find the item.
        let kind = match self.maybe_kind(id) {
            None => return,
            Some(kind) => kind,
        };

        // Iterate over all children.
        let macros_only = self.dep_kind.lock().macros_only();
        let children = self.root.per_def.children.get(self, id).unwrap_or(Lazy::empty());
        for child_index in children.decode((self, sess)) {
            if macros_only {
                continue
            }

            // Get the item.
            if let Some(child_kind) = self.maybe_kind(child_index) {
                match child_kind {
                    EntryKind::MacroDef(..) => {}
                    _ if macros_only => continue,
                    _ => {}
                }

                // Hand off the item to the callback.
                match child_kind {
                    // FIXME(eddyb) Don't encode these in children.
                    EntryKind::ForeignMod => {
                        let child_children =
                            self.root.per_def.children.get(self, child_index)
                                .unwrap_or(Lazy::empty());
                        for child_index in child_children.decode((self, sess)) {
                            if let Some(kind) = self.def_kind(child_index) {
                                callback(def::Export {
                                    res: Res::Def(kind, self.local_def_id(child_index)),
                                    ident: Ident::with_dummy_span(self.item_name(child_index)),
                                    vis: self.get_visibility(child_index),
                                    span: self.root.per_def.span.get(self, child_index).unwrap()
                                        .decode((self, sess)),
                                });
                            }
                        }
                        continue;
                    }
                    EntryKind::Impl(_) => continue,

                    _ => {}
                }

                let def_key = self.def_key(child_index);
                let span = self.get_span(child_index, sess);
                if let (Some(kind), Some(name)) =
                    (self.def_kind(child_index), def_key.disambiguated_data.data.get_opt_name()) {
                    let ident = Ident::with_dummy_span(name);
                    let vis = self.get_visibility(child_index);
                    let def_id = self.local_def_id(child_index);
                    let res = Res::Def(kind, def_id);
                    callback(def::Export { res, ident, vis, span });
                    // For non-re-export structs and variants add their constructors to children.
                    // Re-export lists automatically contain constructors when necessary.
                    match kind {
                        DefKind::Struct => {
                            if let Some(ctor_def_id) = self.get_ctor_def_id(child_index) {
                                let ctor_kind = self.get_ctor_kind(child_index);
                                let ctor_res = Res::Def(
                                    DefKind::Ctor(CtorOf::Struct, ctor_kind),
                                    ctor_def_id,
                                );
                                let vis = self.get_visibility(ctor_def_id.index);
                                callback(def::Export { res: ctor_res, vis, ident, span });
                            }
                        }
                        DefKind::Variant => {
                            // Braced variants, unlike structs, generate unusable names in
                            // value namespace, they are reserved for possible future use.
                            // It's ok to use the variant's id as a ctor id since an
                            // error will be reported on any use of such resolution anyway.
                            let ctor_def_id = self.get_ctor_def_id(child_index).unwrap_or(def_id);
                            let ctor_kind = self.get_ctor_kind(child_index);
                            let ctor_res = Res::Def(
                                DefKind::Ctor(CtorOf::Variant, ctor_kind),
                                ctor_def_id,
                            );
                            let mut vis = self.get_visibility(ctor_def_id.index);
                            if ctor_def_id == def_id && vis == ty::Visibility::Public {
                                // For non-exhaustive variants lower the constructor visibility to
                                // within the crate. We only need this for fictive constructors,
                                // for other constructors correct visibilities
                                // were already encoded in metadata.
                                let attrs = self.get_item_attrs(def_id.index, sess);
                                if attr::contains_name(&attrs, sym::non_exhaustive) {
                                    let crate_def_id = self.local_def_id(CRATE_DEF_INDEX);
                                    vis = ty::Visibility::Restricted(crate_def_id);
                                }
                            }
                            callback(def::Export { res: ctor_res, ident, vis, span });
                        }
                        _ => {}
                    }
                }
            }
        }

        if let EntryKind::Mod(data) = kind {
            for exp in data.decode((self, sess)).reexports.decode((self, sess)) {
                match exp.res {
                    Res::Def(DefKind::Macro(..), _) => {}
                    _ if macros_only => continue,
                    _ => {}
                }
                callback(exp);
            }
        }
    }
/// Iterates over each child of the given item.
Iterates over each child of the given item.
Iterates over each child of the given item .
fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F, sess: &Session)
        where F: FnMut(def::Export<hir::HirId>)
    {
        if let Some(proc_macros_ids) = self.root.proc_macro_data.map(|d| d.decode(self)) {
            /* If we are loading as a proc macro, we want to return the view of this crate
             * as a proc macro crate.
             */
            if id == CRATE_DEF_INDEX {
                for def_index in proc_macros_ids {
                    let raw_macro = self.raw_proc_macro(def_index);
                    let res = Res::Def(
                        DefKind::Macro(macro_kind(raw_macro)),
                        self.local_def_id(def_index),
                    );
                    let ident = Ident::from_str(raw_macro.name());
                    callback(def::Export {
                        ident: ident,
                        res: res,
                        vis: ty::Visibility::Public,
                        span: DUMMY_SP,
                    });
                }
            }
            return
        }
        // Find the item.
        let kind = match self.maybe_kind(id) {
            None => return,
            Some(kind) => kind,
        };
        // Iterate over all children.
        let macros_only = self.dep_kind.lock().macros_only();
        let children = self.root.per_def.children.get(self, id).unwrap_or(Lazy::empty());
        for child_index in children.decode((self, sess)) {
            if macros_only {
                continue
            }
            // Get the item.
            if let Some(child_kind) = self.maybe_kind(child_index) {
                match child_kind {
                    EntryKind::MacroDef(..) => {}
                    _ if macros_only => continue,
                    _ => {}
                }
                // Hand off the item to the callback.
                match child_kind {
                    // FIXME(eddyb) Don't encode these in children.
                    EntryKind::ForeignMod => {
                        let child_children =
                            self.root.per_def.children.get(self, child_index)
                                .unwrap_or(Lazy::empty());
                        for child_index in child_children.decode((self, sess)) {
                            if let Some(kind) = self.def_kind(child_index) {
                                callback(def::Export {
                                    res: Res::Def(kind, self.local_def_id(child_index)),
                                    ident: Ident::with_dummy_span(self.item_name(child_index)),
                                    vis: self.get_visibility(child_index),
                                    span: self.root.per_def.span.get(self, child_index).unwrap()
                                        .decode((self, sess)),
                                });
                            }
                        }
                        continue;
                    }
                    EntryKind::Impl(_) => continue,
                    _ => {}
                }
                let def_key = self.def_key(child_index);
                let span = self.get_span(child_index, sess);
                if let (Some(kind), Some(name)) =
                    (self.def_kind(child_index), def_key.disambiguated_data.data.get_opt_name()) {
                    let ident = Ident::with_dummy_span(name);
                    let vis = self.get_visibility(child_index);
                    let def_id = self.local_def_id(child_index);
                    let res = Res::Def(kind, def_id);
                    callback(def::Export { res, ident, vis, span });
                    // For non-re-export structs and variants add their constructors to children.
                    // Re-export lists automatically contain constructors when necessary.
                    match kind {
                        DefKind::Struct => {
                            if let Some(ctor_def_id) = self.get_ctor_def_id(child_index) {
                                let ctor_kind = self.get_ctor_kind(child_index);
                                let ctor_res = Res::Def(
                                    DefKind::Ctor(CtorOf::Struct, ctor_kind),
                                    ctor_def_id,
                                );
                                let vis = self.get_visibility(ctor_def_id.index);
                                callback(def::Export { res: ctor_res, vis, ident, span });
                            }
                        }
                        DefKind::Variant => {
                            // Braced variants, unlike structs, generate unusable names in
                            // value namespace, they are reserved for possible future use.
                            // It's ok to use the variant's id as a ctor id since an
                            // error will be reported on any use of such resolution anyway.
                            let ctor_def_id = self.get_ctor_def_id(child_index).unwrap_or(def_id);
                            let ctor_kind = self.get_ctor_kind(child_index);
                            let ctor_res = Res::Def(
                                DefKind::Ctor(CtorOf::Variant, ctor_kind),
                                ctor_def_id,
                            );
                            let mut vis = self.get_visibility(ctor_def_id.index);
                            if ctor_def_id == def_id && vis == ty::Visibility::Public {
                                // For non-exhaustive variants lower the constructor visibility to
                                // within the crate. We only need this for fictive constructors,
                                // for other constructors correct visibilities
                                // were already encoded in metadata.
                                let attrs = self.get_item_attrs(def_id.index, sess);
                                if attr::contains_name(&attrs, sym::non_exhaustive) {
                                    let crate_def_id = self.local_def_id(CRATE_DEF_INDEX);
                                    vis = ty::Visibility::Restricted(crate_def_id);
                                }
                            }
                            callback(def::Export { res: ctor_res, ident, vis, span });
                        }
                        _ => {}
                    }
                }
            }
        }
        if let EntryKind::Mod(data) = kind {
            for exp in data.decode((self, sess)).reexports.decode((self, sess)) {
                match exp.res {
                    Res::Def(DefKind::Macro(..), _) => {}
                    _ if macros_only => continue,
                    _ => {}
                }
                callback(exp);
            }
        }
    }
fn each_child_of_item < F > ( & self , id : DefIndex , mut callback : F , sess : & Session ) where F : FnMut ( def :: Export < hir :: HirId > ) { if let Some ( proc_macros_ids ) = self . root . proc_macro_data . map ( | d | d . decode ( self ) ) { /* If we are loading as a proc macro, we want to return the view of this crate
             * as a proc macro crate.
             */ if id == CRATE_DEF_INDEX { for def_index in proc_macros_ids { let raw_macro = self . raw_proc_macro ( def_index ) ; let res = Res :: Def ( DefKind :: Macro ( macro_kind ( raw_macro ) ) , self . local_def_id ( def_index ) , ) ; let ident = Ident :: from_str ( raw_macro . name ( ) ) ; callback ( def :: Export { ident : ident , res : res , vis : ty :: Visibility :: Public , span : DUMMY_SP , } ) ; } } return } // Find the item. let kind = match self . maybe_kind ( id ) { None => return , Some ( kind ) => kind , } ; // Iterate over all children. let macros_only = self . dep_kind . lock ( ) . macros_only ( ) ; let children = self . root . per_def . children . get ( self , id ) . unwrap_or ( Lazy :: empty ( ) ) ; for child_index in children . decode ( ( self , sess ) ) { if macros_only { continue } // Get the item. if let Some ( child_kind ) = self . maybe_kind ( child_index ) { match child_kind { EntryKind :: MacroDef ( .. ) => { } _ if macros_only => continue , _ => { } } // Hand off the item to the callback. match child_kind { // FIXME(eddyb) Don't encode these in children. EntryKind :: ForeignMod => { let child_children = self . root . per_def . children . get ( self , child_index ) . unwrap_or ( Lazy :: empty ( ) ) ; for child_index in child_children . decode ( ( self , sess ) ) { if let Some ( kind ) = self . def_kind ( child_index ) { callback ( def :: Export { res : Res :: Def ( kind , self . local_def_id ( child_index ) ) , ident : Ident :: with_dummy_span ( self . item_name ( child_index ) ) , vis : self . get_visibility ( child_index ) , span : self . root . per_def . span . get ( self , child_index ) . unwrap ( ) . decode ( ( self , sess ) ) , } ) ; } } continue ; } EntryKind :: Impl ( _ ) => continue , _ => { } } let def_key = self . def_key ( child_index ) ; let span = self . get_span ( child_index , sess ) ; if let ( Some ( kind ) , Some ( name ) ) = ( self . def_kind ( child_index ) , def_key . disambiguated_data . data . get_opt_name ( ) ) { let ident = Ident :: with_dummy_span ( name ) ; let vis = self . get_visibility ( child_index ) ; let def_id = self . local_def_id ( child_index ) ; let res = Res :: Def ( kind , def_id ) ; callback ( def :: Export { res , ident , vis , span } ) ; // For non-re-export structs and variants add their constructors to children. // Re-export lists automatically contain constructors when necessary. match kind { DefKind :: Struct => { if let Some ( ctor_def_id ) = self . get_ctor_def_id ( child_index ) { let ctor_kind = self . get_ctor_kind ( child_index ) ; let ctor_res = Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ctor_kind ) , ctor_def_id , ) ; let vis = self . get_visibility ( ctor_def_id . index ) ; callback ( def :: Export { res : ctor_res , vis , ident , span } ) ; } } DefKind :: Variant => { // Braced variants, unlike structs, generate unusable names in // value namespace, they are reserved for possible future use. // It's ok to use the variant's id as a ctor id since an // error will be reported on any use of such resolution anyway. let ctor_def_id = self . get_ctor_def_id ( child_index ) . unwrap_or ( def_id ) ; let ctor_kind = self . get_ctor_kind ( child_index ) ; let ctor_res = Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , ctor_kind ) , ctor_def_id , ) ; let mut vis = self . get_visibility ( ctor_def_id . index ) ; if ctor_def_id == def_id && vis == ty :: Visibility :: Public { // For non-exhaustive variants lower the constructor visibility to // within the crate. We only need this for fictive constructors, // for other constructors correct visibilities // were already encoded in metadata. let attrs = self . get_item_attrs ( def_id . index , sess ) ; if attr :: contains_name ( & attrs , sym :: non_exhaustive ) { let crate_def_id = self . local_def_id ( CRATE_DEF_INDEX ) ; vis = ty :: Visibility :: Restricted ( crate_def_id ) ; } } callback ( def :: Export { res : ctor_res , ident , vis , span } ) ; } _ => { } } } } } if let EntryKind :: Mod ( data ) = kind { for exp in data . decode ( ( self , sess ) ) . reexports . decode ( ( self , sess ) ) { match exp . res { Res :: Def ( DefKind :: Macro ( .. ) , _ ) => { } _ if macros_only => continue , _ => { } } callback ( exp ) ; } } }
Iterates over each child of the given item.
Iterates over each child of the given item .
&self
id
DefIndex
callback
F
sess
&Session