@@ -21,7 +21,7 @@ use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
21
21
use rustc_hir:: diagnostic_items:: DiagnosticItems ;
22
22
use rustc_hir:: lang_items;
23
23
use rustc_index:: vec:: { Idx , IndexVec } ;
24
- use rustc_middle:: hir :: exports :: Export ;
24
+ use rustc_middle:: metadata :: ModChild ;
25
25
use rustc_middle:: middle:: exported_symbols:: { ExportedSymbol , SymbolExportLevel } ;
26
26
use rustc_middle:: mir:: interpret:: { AllocDecodingSession , AllocDecodingState } ;
27
27
use rustc_middle:: mir:: { self , Body , Promoted } ;
@@ -1074,33 +1074,38 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1074
1074
}
1075
1075
}
1076
1076
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
+ ) {
1079
1087
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.
1083
1090
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 ) {
1086
1092
let raw_macro = self . raw_proc_macro ( def_index) ;
1087
1093
let res = Res :: Def (
1088
1094
DefKind :: Macro ( macro_kind ( raw_macro) ) ,
1089
1095
self . local_def_id ( def_index) ,
1090
1096
) ;
1091
1097
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
+ } ) ;
1093
1104
}
1094
1105
}
1095
1106
return ;
1096
1107
}
1097
1108
1098
- // Find the item.
1099
- let kind = match self . maybe_kind ( id) {
1100
- None => return ,
1101
- Some ( kind) => kind,
1102
- } ;
1103
-
1104
1109
// Iterate over all children.
1105
1110
if let Some ( children) = self . root . tables . children . get ( self , id) {
1106
1111
for child_index in children. decode ( ( self , sess) ) {
@@ -1116,7 +1121,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1116
1121
let vis = self . get_visibility ( child_index) ;
1117
1122
let span = self . get_span ( child_index, sess) ;
1118
1123
1119
- callback ( Export { ident, res, vis, span } ) ;
1124
+ callback ( ModChild { ident, res, vis, span } ) ;
1120
1125
1121
1126
// For non-re-export structs and variants add their constructors to children.
1122
1127
// Re-export lists automatically contain constructors when necessary.
@@ -1128,7 +1133,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1128
1133
let ctor_res =
1129
1134
Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ctor_kind) , ctor_def_id) ;
1130
1135
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 } ) ;
1132
1137
}
1133
1138
}
1134
1139
DefKind :: Variant => {
@@ -1153,18 +1158,22 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1153
1158
vis = ty:: Visibility :: Restricted ( crate_def_id) ;
1154
1159
}
1155
1160
}
1156
- callback ( Export { res : ctor_res, ident , vis, span } ) ;
1161
+ callback ( ModChild { ident , res : ctor_res, vis, span } ) ;
1157
1162
}
1158
1163
_ => { }
1159
1164
}
1160
1165
}
1161
1166
}
1162
1167
}
1163
1168
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
+ }
1167
1174
}
1175
+ EntryKind :: Enum ( ..) | EntryKind :: Trait ( ..) => { }
1176
+ _ => bug ! ( "`for_each_module_child` is called on a non-module: {:?}" , self . def_kind( id) ) ,
1168
1177
}
1169
1178
}
1170
1179
0 commit comments