@@ -24,7 +24,7 @@ use rustc_span::{Ident, Span, Symbol, kw, sym};
24
24
use smallvec:: SmallVec ;
25
25
use tracing:: debug;
26
26
27
- use crate :: Namespace :: * ;
27
+ use crate :: Namespace :: { self , * } ;
28
28
use crate :: diagnostics:: { DiagMode , Suggestion , import_candidates} ;
29
29
use crate :: errors:: {
30
30
CannotBeReexportedCratePublic , CannotBeReexportedCratePublicNS , CannotBeReexportedPrivate ,
@@ -337,13 +337,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
337
337
pub ( crate ) fn try_define (
338
338
& mut self ,
339
339
module : Module < ' ra > ,
340
- key : BindingKey ,
340
+ ident : Ident ,
341
+ ns : Namespace ,
341
342
binding : NameBinding < ' ra > ,
342
343
warn_ambiguity : bool ,
343
344
) -> Result < ( ) , NameBinding < ' ra > > {
344
345
let res = binding. res ( ) ;
345
- self . check_reserved_macro_name ( key . ident , res) ;
346
+ self . check_reserved_macro_name ( ident, res) ;
346
347
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
+ } ) ;
347
351
self . update_resolution ( module, key, warn_ambiguity, |this, resolution| {
348
352
if let Some ( old_binding) = resolution. best_binding ( ) {
349
353
if res == Res :: Err && old_binding. res ( ) != Res :: Err {
@@ -382,7 +386,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
382
386
( old_glob @ true , false ) | ( old_glob @ false , true ) => {
383
387
let ( glob_binding, non_glob_binding) =
384
388
if old_glob { ( old_binding, binding) } else { ( binding, old_binding) } ;
385
- if key . ns == MacroNS
389
+ if ns == MacroNS
386
390
&& non_glob_binding. expansion != LocalExpnId :: ROOT
387
391
&& glob_binding. res ( ) != non_glob_binding. res ( )
388
392
{
@@ -488,10 +492,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
488
492
} ;
489
493
if self . is_accessible_from ( binding. vis , scope) {
490
494
let imported_binding = self . import ( binding, * import) ;
491
- let key = BindingKey { ident, ..key } ;
492
495
let _ = self . try_define (
493
496
import. parent_scope . module ,
494
- key,
497
+ ident,
498
+ key. ns ,
495
499
imported_binding,
496
500
warn_ambiguity,
497
501
) ;
@@ -513,11 +517,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
513
517
let dummy_binding = self . dummy_binding ;
514
518
let dummy_binding = self . import ( dummy_binding, import) ;
515
519
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
+ }
521
529
} ) ;
522
530
self . record_use ( target, dummy_binding, Used :: Other ) ;
523
531
} else if import. imported_module . get ( ) . is_none ( ) {
@@ -879,7 +887,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
879
887
PendingBinding :: Ready ( Some ( imported_binding) )
880
888
}
881
889
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.
883
891
if target. name != kw:: Underscore {
884
892
let key = BindingKey :: new ( target, ns) ;
885
893
this. update_resolution ( parent, key, false , |_, resolution| {
@@ -1494,7 +1502,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1494
1502
. is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
1495
1503
let _ = self . try_define (
1496
1504
import. parent_scope . module ,
1497
- key,
1505
+ key. ident ,
1506
+ key. ns ,
1498
1507
imported_binding,
1499
1508
warn_ambiguity,
1500
1509
) ;
0 commit comments