@@ -77,6 +77,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
7777parent : Module < ' ra > ,
7878ident : Ident ,
7979ns : Namespace ,
80+ child_index : usize ,
8081res : Res ,
8182vis : Visibility < DefId > ,
8283span : 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
9392if self
9493. resolution_or_default ( parent, key)
9594. borrow_mut_unchecked ( )
@@ -233,9 +232,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
233232}
234233
235234pub ( 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 ( ) {
237236let 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 ,
245244child : & ModChild ,
246245parent_scope : ParentScope < ' ra > ,
246+ child_index : usize ,
247247) {
248248let parent = parent_scope. module ;
249249let 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+ }
276278Res :: Def (
277279DefKind :: 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) ,
285287Res :: 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}
288290Res :: Def (
289291DefKind :: TyParam
0 commit comments