@@ -77,6 +77,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
7777 parent : Module < ' ra > ,
7878 ident : Ident ,
7979 ns : Namespace ,
80+ child_index : usize ,
8081 res : Res ,
8182 vis : Visibility < DefId > ,
8283 span : Span ,
@@ -86,10 +87,8 @@ 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 =
91+ BindingKey :: new_disambiguated ( ident, ns, || ( child_index + 1 ) . try_into ( ) . unwrap ( ) ) ; // 0 indicates no underscore
9392 if self
9493 . resolution_or_default ( parent, key)
9594 . borrow_mut_unchecked ( )
@@ -233,9 +232,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
233232 }
234233
235234 pub ( crate ) fn build_reduced_graph_external ( & self , module : Module < ' ra > ) {
236- for child in self . tcx . module_children ( module. def_id ( ) ) {
235+ for ( i , child) in self . tcx . module_children ( module. def_id ( ) ) . into_iter ( ) . enumerate ( ) {
237236 let parent_scope = ParentScope :: module ( module, self . arenas ) ;
238- self . build_reduced_graph_for_external_crate_res ( child, parent_scope)
237+ self . build_reduced_graph_for_external_crate_res ( child, parent_scope, i )
239238 }
240239 }
241240
@@ -244,6 +243,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
244243 & self ,
245244 child : & ModChild ,
246245 parent_scope : ParentScope < ' ra > ,
246+ child_index : usize ,
247247 ) {
248248 let parent = parent_scope. module ;
249249 let ModChild { ident, res, vis, ref reexport_chain } = * child;
@@ -272,7 +272,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
272272 _,
273273 )
274274 | Res :: PrimTy ( ..)
275- | Res :: ToolMod => self . define_extern ( parent, ident, TypeNS , res, vis, span, expansion) ,
275+ | Res :: ToolMod => {
276+ self . define_extern ( parent, ident, TypeNS , child_index, res, vis, span, expansion)
277+ }
276278 Res :: Def (
277279 DefKind :: Fn
278280 | DefKind :: AssocFn
@@ -281,9 +283,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
281283 | DefKind :: AssocConst
282284 | DefKind :: Ctor ( ..) ,
283285 _,
284- ) => self . define_extern ( parent, ident, ValueNS , res, vis, span, expansion) ,
286+ ) => self . define_extern ( parent, ident, ValueNS , child_index , res, vis, span, expansion) ,
285287 Res :: Def ( DefKind :: Macro ( ..) , _) | Res :: NonMacroAttr ( ..) => {
286- self . define_extern ( parent, ident, MacroNS , res, vis, span, expansion)
288+ self . define_extern ( parent, ident, MacroNS , child_index , res, vis, span, expansion)
287289 }
288290 Res :: Def (
289291 DefKind :: TyParam
0 commit comments