@@ -25,7 +25,7 @@ use rustc_span::{Ident, Span, Symbol, kw, sym};
2525use smallvec:: SmallVec ;
2626use tracing:: debug;
2727
28- use crate :: Namespace :: { self , * } ;
28+ use crate :: Namespace :: * ;
2929use crate :: diagnostics:: { DiagMode , Suggestion , import_candidates} ;
3030use crate :: errors:: {
3131 CannotBeReexportedCratePublic , CannotBeReexportedCratePublicNS , CannotBeReexportedPrivate ,
@@ -338,20 +338,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
338338 pub ( crate ) fn try_define (
339339 & mut self ,
340340 module : Module < ' ra > ,
341- ident : Ident ,
342- ns : Namespace ,
341+ key : BindingKey ,
343342 binding : NameBinding < ' ra > ,
344343 warn_ambiguity : bool ,
345344 ) -> Result < ( ) , NameBinding < ' ra > > {
346345 let res = binding. res ( ) ;
347- self . check_reserved_macro_name ( ident, res) ;
346+ self . check_reserved_macro_name ( key . ident , res) ;
348347 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- } ) ;
355348 self . update_resolution ( module, key, warn_ambiguity, |this, resolution| {
356349 if let Some ( old_binding) = resolution. best_binding ( ) {
357350 if res == Res :: Err && old_binding. res ( ) != Res :: Err {
@@ -390,7 +383,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
390383 ( old_glob @ true , false ) | ( old_glob @ false , true ) => {
391384 let ( glob_binding, non_glob_binding) =
392385 if old_glob { ( old_binding, binding) } else { ( binding, old_binding) } ;
393- if ns == MacroNS
386+ if key . ns == MacroNS
394387 && non_glob_binding. expansion != LocalExpnId :: ROOT
395388 && glob_binding. res ( ) != non_glob_binding. res ( )
396389 {
@@ -496,10 +489,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
496489 } ;
497490 if self . is_accessible_from ( binding. vis , scope) {
498491 let imported_binding = self . import ( binding, * import) ;
492+ let key = BindingKey { ident, ..key } ;
499493 let _ = self . try_define (
500494 import. parent_scope . module ,
501- ident,
502- key. ns ,
495+ key,
503496 imported_binding,
504497 warn_ambiguity,
505498 ) ;
@@ -521,15 +514,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
521514 let dummy_binding = self . dummy_binding ;
522515 let dummy_binding = self . import ( dummy_binding, import) ;
523516 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+ } )
533522 } ) ;
534523 self . record_use ( target, dummy_binding, Used :: Other ) ;
535524 } else if import. imported_module . get ( ) . is_none ( ) {
@@ -906,7 +895,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
906895 PendingBinding :: Ready ( Some ( imported_binding) )
907896 }
908897 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.
910899 if target. name != kw:: Underscore {
911900 let key = BindingKey :: new ( target, ns) ;
912901 this. update_resolution ( parent, key, false , |_, resolution| {
@@ -1521,8 +1510,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15211510 . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
15221511 let _ = self . try_define (
15231512 import. parent_scope . module ,
1524- key. ident ,
1525- key. ns ,
1513+ key,
15261514 imported_binding,
15271515 warn_ambiguity,
15281516 ) ;
0 commit comments