@@ -25,7 +25,7 @@ use rustc_span::{Ident, Span, Symbol, kw, sym};
25
25
use smallvec:: SmallVec ;
26
26
use tracing:: debug;
27
27
28
- use crate :: Namespace :: { self , * } ;
28
+ use crate :: Namespace :: * ;
29
29
use crate :: diagnostics:: { DiagMode , Suggestion , import_candidates} ;
30
30
use crate :: errors:: {
31
31
CannotBeReexportedCratePublic , CannotBeReexportedCratePublicNS , CannotBeReexportedPrivate ,
@@ -338,20 +338,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
338
338
pub ( crate ) fn try_define (
339
339
& mut self ,
340
340
module : Module < ' ra > ,
341
- ident : Ident ,
342
- ns : Namespace ,
341
+ key : BindingKey ,
343
342
binding : NameBinding < ' ra > ,
344
343
warn_ambiguity : bool ,
345
344
) -> Result < ( ) , NameBinding < ' ra > > {
346
345
let res = binding. res ( ) ;
347
- self . check_reserved_macro_name ( ident, res) ;
346
+ self . check_reserved_macro_name ( key . ident , res) ;
348
347
self . set_binding_parent_module ( binding, module) ;
349
- // Even if underscore names cannot be looked up, we still need to add them to modules,
350
- // because they can be fetched by glob imports from those modules, and bring traits
351
- // into scope both directly and through glob imports.
352
- let key = BindingKey :: new_disambiguated ( ident, ns, || {
353
- ( module. 0 . 0 . lazy_resolutions . borrow ( ) . len ( ) + 1 ) . try_into ( ) . unwrap ( )
354
- } ) ;
355
348
self . update_resolution ( module, key, warn_ambiguity, |this, resolution| {
356
349
if let Some ( old_binding) = resolution. best_binding ( ) {
357
350
if res == Res :: Err && old_binding. res ( ) != Res :: Err {
@@ -390,7 +383,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
390
383
( old_glob @ true , false ) | ( old_glob @ false , true ) => {
391
384
let ( glob_binding, non_glob_binding) =
392
385
if old_glob { ( old_binding, binding) } else { ( binding, old_binding) } ;
393
- if ns == MacroNS
386
+ if key . ns == MacroNS
394
387
&& non_glob_binding. expansion != LocalExpnId :: ROOT
395
388
&& glob_binding. res ( ) != non_glob_binding. res ( )
396
389
{
@@ -496,10 +489,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
496
489
} ;
497
490
if self . is_accessible_from ( binding. vis , scope) {
498
491
let imported_binding = self . import ( binding, * import) ;
492
+ let key = BindingKey { ident, ..key } ;
499
493
let _ = self . try_define (
500
494
import. parent_scope . module ,
501
- ident,
502
- key. ns ,
495
+ key,
503
496
imported_binding,
504
497
warn_ambiguity,
505
498
) ;
@@ -521,15 +514,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
521
514
let dummy_binding = self . dummy_binding ;
522
515
let dummy_binding = self . import ( dummy_binding, import) ;
523
516
self . per_ns ( |this, ns| {
524
- let module = import. parent_scope . module ;
525
- let _ = this. try_define ( module, target, ns, dummy_binding, false ) ;
526
- // Don't remove underscores from `single_imports`, they were never added.
527
- if target. name != kw:: Underscore {
528
- let key = BindingKey :: new ( target, ns) ;
529
- this. update_resolution ( module, key, false , |_, resolution| {
530
- resolution. single_imports . swap_remove ( & import) ;
531
- } )
532
- }
517
+ let key = BindingKey :: new ( target, ns) ;
518
+ let _ = this. try_define ( import. parent_scope . module , key, dummy_binding, false ) ;
519
+ this. update_resolution ( import. parent_scope . module , key, false , |_, resolution| {
520
+ resolution. single_imports . swap_remove ( & import) ;
521
+ } )
533
522
} ) ;
534
523
self . record_use ( target, dummy_binding, Used :: Other ) ;
535
524
} else if import. imported_module . get ( ) . is_none ( ) {
@@ -906,7 +895,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
906
895
PendingBinding :: Ready ( Some ( imported_binding) )
907
896
}
908
897
Err ( Determinacy :: Determined ) => {
909
- // Don't remove underscores from `single_imports`, they were never added.
898
+ // Don't update the resolution for underscores, because it was never added.
910
899
if target. name != kw:: Underscore {
911
900
let key = BindingKey :: new ( target, ns) ;
912
901
this. update_resolution ( parent, key, false , |_, resolution| {
@@ -1521,8 +1510,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1521
1510
. is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
1522
1511
let _ = self . try_define (
1523
1512
import. parent_scope . module ,
1524
- key. ident ,
1525
- key. ns ,
1513
+ key,
1526
1514
imported_binding,
1527
1515
warn_ambiguity,
1528
1516
) ;
0 commit comments