@@ -24,7 +24,7 @@ use rustc_span::{Ident, Span, Symbol, kw, sym};
2424use smallvec:: SmallVec ;
2525use tracing:: debug;
2626
27- use crate :: Namespace :: * ;
27+ use crate :: Namespace :: { self , * } ;
2828use crate :: diagnostics:: { DiagMode , Suggestion , import_candidates} ;
2929use crate :: errors:: {
3030 CannotBeReexportedCratePublic , CannotBeReexportedCratePublicNS , CannotBeReexportedPrivate ,
@@ -337,13 +337,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
337337 pub ( crate ) fn try_define (
338338 & mut self ,
339339 module : Module < ' ra > ,
340- key : BindingKey ,
340+ ident : Ident ,
341+ ns : Namespace ,
341342 binding : NameBinding < ' ra > ,
342343 warn_ambiguity : bool ,
343344 ) -> Result < ( ) , NameBinding < ' ra > > {
344345 let res = binding. res ( ) ;
345- self . check_reserved_macro_name ( key . ident , res) ;
346+ self . check_reserved_macro_name ( ident, res) ;
346347 self . set_binding_parent_module ( binding, module) ;
348+ let key = BindingKey :: new_disambiguated ( ident, ns, || {
349+ ( module. 0 . 0 . lazy_resolutions . borrow ( ) . len ( ) + 1 ) . try_into ( ) . unwrap ( )
350+ } ) ;
347351 self . update_resolution ( module, key, warn_ambiguity, |this, resolution| {
348352 if let Some ( old_binding) = resolution. best_binding ( ) {
349353 if res == Res :: Err && old_binding. res ( ) != Res :: Err {
@@ -382,7 +386,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
382386 ( old_glob @ true , false ) | ( old_glob @ false , true ) => {
383387 let ( glob_binding, non_glob_binding) =
384388 if old_glob { ( old_binding, binding) } else { ( binding, old_binding) } ;
385- if key . ns == MacroNS
389+ if ns == MacroNS
386390 && non_glob_binding. expansion != LocalExpnId :: ROOT
387391 && glob_binding. res ( ) != non_glob_binding. res ( )
388392 {
@@ -488,10 +492,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
488492 } ;
489493 if self . is_accessible_from ( binding. vis , scope) {
490494 let imported_binding = self . import ( binding, * import) ;
491- let key = BindingKey { ident, ..key } ;
492495 let _ = self . try_define (
493496 import. parent_scope . module ,
494- key,
497+ ident,
498+ key. ns ,
495499 imported_binding,
496500 warn_ambiguity,
497501 ) ;
@@ -513,11 +517,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
513517 let dummy_binding = self . dummy_binding ;
514518 let dummy_binding = self . import ( dummy_binding, import) ;
515519 self . per_ns ( |this, ns| {
516- let key = BindingKey :: new ( target, ns) ;
517- let _ = this. try_define ( import. parent_scope . module , key, dummy_binding, false ) ;
518- this. update_resolution ( import. parent_scope . module , key, false , |_, resolution| {
519- resolution. single_imports . swap_remove ( & import) ;
520- } )
520+ let module = import. parent_scope . module ;
521+ let _ = this. try_define ( module, target, ns, dummy_binding, false ) ;
522+ // Don't remove underscores from `single_imports`, they were never added.
523+ if target. name != kw:: Underscore {
524+ let key = BindingKey :: new ( target, ns) ;
525+ this. update_resolution ( module, key, false , |_, resolution| {
526+ resolution. single_imports . swap_remove ( & import) ;
527+ } )
528+ }
521529 } ) ;
522530 self . record_use ( target, dummy_binding, Used :: Other ) ;
523531 } else if import. imported_module . get ( ) . is_none ( ) {
@@ -879,7 +887,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
879887 PendingBinding :: Ready ( Some ( imported_binding) )
880888 }
881889 Err ( Determinacy :: Determined ) => {
882- // Don't update the resolution for underscores, because it was never added.
890+ // Don't remove underscores from `single_imports`, they were never added.
883891 if target. name != kw:: Underscore {
884892 let key = BindingKey :: new ( target, ns) ;
885893 this. update_resolution ( parent, key, false , |_, resolution| {
@@ -1494,7 +1502,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14941502 . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
14951503 let _ = self . try_define (
14961504 import. parent_scope . module ,
1497- key,
1505+ key. ident ,
1506+ key. ns ,
14981507 imported_binding,
14991508 warn_ambiguity,
15001509 ) ;
0 commit comments