@@ -77,6 +77,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
7777 parent : Module < ' ra > ,
7878 ident : Ident ,
7979 ns : Namespace ,
80+ disambiguator : u32 ,
8081 res : Res ,
8182 vis : Visibility < DefId > ,
8283 span : Span ,
@@ -86,10 +87,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
8687 // Even if underscore names cannot be looked up, we still need to add them to modules,
8788 // because they can be fetched by glob imports from those modules, and bring traits
8889 // into scope both directly and through glob imports.
89- let key = BindingKey :: new_disambiguated ( ident, ns, || {
90- parent. underscore_disambiguator . update_unchecked ( |d| d + 1 ) ;
91- parent. underscore_disambiguator . get ( )
92- } ) ;
90+ let key = BindingKey :: new_disambiguated ( ident, ns, || disambiguator) ;
9391 if self
9492 . resolution_or_default ( parent, key)
9593 . borrow_mut_unchecked ( )
@@ -233,9 +231,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
233231 }
234232
235233 pub ( crate ) fn build_reduced_graph_external ( & self , module : Module < ' ra > ) {
236- for child in self . tcx . module_children ( module. def_id ( ) ) {
234+ for ( i , child) in self . tcx . module_children ( module. def_id ( ) ) . into_iter ( ) . enumerate ( ) {
237235 let parent_scope = ParentScope :: module ( module, self . arenas ) ;
238- self . build_reduced_graph_for_external_crate_res ( child, parent_scope)
236+ self . build_reduced_graph_for_external_crate_res (
237+ child,
238+ parent_scope,
239+ i. try_into ( ) . unwrap ( ) ,
240+ )
239241 }
240242 }
241243
@@ -244,6 +246,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
244246 & self ,
245247 child : & ModChild ,
246248 parent_scope : ParentScope < ' ra > ,
249+ child_index : u32 ,
247250 ) {
248251 let parent = parent_scope. module ;
249252 let ModChild { ident, res, vis, ref reexport_chain } = * child;
@@ -272,7 +275,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
272275 _,
273276 )
274277 | Res :: PrimTy ( ..)
275- | Res :: ToolMod => self . define_extern ( parent, ident, TypeNS , res, vis, span, expansion) ,
278+ | Res :: ToolMod => self . define_extern (
279+ parent,
280+ ident,
281+ TypeNS ,
282+ child_index + 1 , // 0 indicates no underscore
283+ res,
284+ vis,
285+ span,
286+ expansion,
287+ ) ,
276288 Res :: Def (
277289 DefKind :: Fn
278290 | DefKind :: AssocFn
@@ -281,10 +293,26 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
281293 | DefKind :: AssocConst
282294 | DefKind :: Ctor ( ..) ,
283295 _,
284- ) => self . define_extern ( parent, ident, ValueNS , res, vis, span, expansion) ,
285- Res :: Def ( DefKind :: Macro ( ..) , _) | Res :: NonMacroAttr ( ..) => {
286- self . define_extern ( parent, ident, MacroNS , res, vis, span, expansion)
287- }
296+ ) => self . define_extern (
297+ parent,
298+ ident,
299+ ValueNS ,
300+ child_index + 1 , // 0 indicates no underscore
301+ res,
302+ vis,
303+ span,
304+ expansion,
305+ ) ,
306+ Res :: Def ( DefKind :: Macro ( ..) , _) | Res :: NonMacroAttr ( ..) => self . define_extern (
307+ parent,
308+ ident,
309+ MacroNS ,
310+ child_index + 1 , // 0 indicates no underscore
311+ res,
312+ vis,
313+ span,
314+ expansion,
315+ ) ,
288316 Res :: Def (
289317 DefKind :: TyParam
290318 | DefKind :: ConstParam
0 commit comments