@@ -21,7 +21,7 @@ use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
2121use rustc_hir:: diagnostic_items:: DiagnosticItems ;
2222use rustc_hir:: lang_items;
2323use rustc_index:: vec:: { Idx , IndexVec } ;
24- use rustc_middle:: hir :: exports :: Export ;
24+ use rustc_middle:: metadata :: ModChild ;
2525use rustc_middle:: middle:: exported_symbols:: { ExportedSymbol , SymbolExportLevel } ;
2626use rustc_middle:: mir:: interpret:: { AllocDecodingSession , AllocDecodingState } ;
2727use rustc_middle:: mir:: { self , Body , Promoted } ;
@@ -1074,33 +1074,38 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10741074 }
10751075 }
10761076
1077- /// Iterates over each child of the given item.
1078- fn each_child_of_item ( & self , id : DefIndex , mut callback : impl FnMut ( Export ) , sess : & Session ) {
1077+ /// Iterates over all named children of the given module,
1078+ /// including both proper items and reexports.
1079+ /// Module here is understood in name resolution sense - it can be a `mod` item,
1080+ /// or a crate root, or an enum, or a trait.
1081+ fn for_each_module_child (
1082+ & self ,
1083+ id : DefIndex ,
1084+ mut callback : impl FnMut ( ModChild ) ,
1085+ sess : & Session ,
1086+ ) {
10791087 if let Some ( data) = & self . root . proc_macro_data {
1080- /* If we are loading as a proc macro, we want to return the view of this crate
1081- * as a proc macro crate.
1082- */
1088+ // If we are loading as a proc macro, we want to return
1089+ // the view of this crate as a proc macro crate.
10831090 if id == CRATE_DEF_INDEX {
1084- let macros = data. macros . decode ( self ) ;
1085- for def_index in macros {
1091+ for def_index in data. macros . decode ( self ) {
10861092 let raw_macro = self . raw_proc_macro ( def_index) ;
10871093 let res = Res :: Def (
10881094 DefKind :: Macro ( macro_kind ( raw_macro) ) ,
10891095 self . local_def_id ( def_index) ,
10901096 ) ;
10911097 let ident = self . item_ident ( def_index, sess) ;
1092- callback ( Export { ident, res, vis : ty:: Visibility :: Public , span : ident. span } ) ;
1098+ callback ( ModChild {
1099+ ident,
1100+ res,
1101+ vis : ty:: Visibility :: Public ,
1102+ span : ident. span ,
1103+ } ) ;
10931104 }
10941105 }
10951106 return ;
10961107 }
10971108
1098- // Find the item.
1099- let kind = match self . maybe_kind ( id) {
1100- None => return ,
1101- Some ( kind) => kind,
1102- } ;
1103-
11041109 // Iterate over all children.
11051110 if let Some ( children) = self . root . tables . children . get ( self , id) {
11061111 for child_index in children. decode ( ( self , sess) ) {
@@ -1116,7 +1121,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11161121 let vis = self . get_visibility ( child_index) ;
11171122 let span = self . get_span ( child_index, sess) ;
11181123
1119- callback ( Export { ident, res, vis, span } ) ;
1124+ callback ( ModChild { ident, res, vis, span } ) ;
11201125
11211126 // For non-re-export structs and variants add their constructors to children.
11221127 // Re-export lists automatically contain constructors when necessary.
@@ -1128,7 +1133,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11281133 let ctor_res =
11291134 Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ctor_kind) , ctor_def_id) ;
11301135 let vis = self . get_visibility ( ctor_def_id. index ) ;
1131- callback ( Export { res : ctor_res, vis, ident , span } ) ;
1136+ callback ( ModChild { ident , res : ctor_res, vis, span } ) ;
11321137 }
11331138 }
11341139 DefKind :: Variant => {
@@ -1153,18 +1158,22 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11531158 vis = ty:: Visibility :: Restricted ( crate_def_id) ;
11541159 }
11551160 }
1156- callback ( Export { res : ctor_res, ident , vis, span } ) ;
1161+ callback ( ModChild { ident , res : ctor_res, vis, span } ) ;
11571162 }
11581163 _ => { }
11591164 }
11601165 }
11611166 }
11621167 }
11631168
1164- if let EntryKind :: Mod ( exports) = kind {
1165- for exp in exports. decode ( ( self , sess) ) {
1166- callback ( exp) ;
1169+ match self . kind ( id) {
1170+ EntryKind :: Mod ( exports) => {
1171+ for exp in exports. decode ( ( self , sess) ) {
1172+ callback ( exp) ;
1173+ }
11671174 }
1175+ EntryKind :: Enum ( ..) | EntryKind :: Trait ( ..) => { }
1176+ _ => bug ! ( "`for_each_module_child` is called on a non-module: {:?}" , self . def_kind( id) ) ,
11681177 }
11691178 }
11701179
0 commit comments