@@ -22,7 +22,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
2222use rustc_span:: hygiene:: LocalExpnId ;
2323use rustc_span:: { Ident , Span , Symbol , kw, sym} ;
2424use smallvec:: SmallVec ;
25- use tracing:: debug;
25+ use tracing:: { debug, instrument } ;
2626
2727use crate :: Determinacy :: { self , * } ;
2828use crate :: Namespace :: * ;
@@ -242,21 +242,20 @@ pub(crate) struct NameResolution<'ra> {
242242 /// Single imports that may define the name in the namespace.
243243 /// Imports are arena-allocated, so it's ok to use pointers as keys.
244244 pub single_imports : FxIndexSet < Import < ' ra > > ,
245- /// The least shadowable known binding for this name, or None if there are no known bindings.
246- pub binding : Option < NameBinding < ' ra > > ,
247- pub shadowed_glob : Option < NameBinding < ' ra > > ,
245+ /// The least shadowable known non-glob binding for this name, or None if there are no known bindings.
246+ pub non_glob_binding : Option < NameBinding < ' ra > > ,
247+ pub glob_binding : Option < NameBinding < ' ra > > ,
248248}
249249
250250impl < ' ra > NameResolution < ' ra > {
251251 /// Returns the binding for the name if it is known or None if it not known.
252252 pub ( crate ) fn binding ( & self ) -> Option < NameBinding < ' ra > > {
253- self . binding . and_then ( |binding| {
254- if !binding. is_glob_import ( ) || self . single_imports . is_empty ( ) {
255- Some ( binding)
256- } else {
257- None
258- }
259- } )
253+ self . non_glob_binding
254+ . or_else ( || if self . single_imports . is_empty ( ) { self . glob_binding } else { None } )
255+ }
256+
257+ pub ( crate ) fn late_binding ( & self ) -> Option < NameBinding < ' ra > > {
258+ self . non_glob_binding . or_else ( || self . glob_binding )
260259 }
261260}
262261
@@ -338,7 +337,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
338337 self . check_reserved_macro_name ( key. ident , res) ;
339338 self . set_binding_parent_module ( binding, module) ;
340339 self . update_resolution ( module, key, warn_ambiguity, |this, resolution| {
341- if let Some ( old_binding) = resolution. binding {
340+ if let Some ( old_binding) = resolution. non_glob_binding {
342341 if res == Res :: Err && old_binding. res ( ) != Res :: Err {
343342 // Do not override real bindings with `Res::Err`s from error recovery.
344343 return Ok ( ( ) ) ;
@@ -355,19 +354,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
355354 // We should replace the `old_binding` with `binding` regardless
356355 // of whether they has same resolution or not when they are
357356 // imported from the same glob-import statement.
358- resolution. binding = Some ( binding) ;
357+ resolution. non_glob_binding = Some ( binding) ;
359358 } else if res != old_binding. res ( ) {
360- resolution. binding = Some ( this. new_ambiguity_binding (
359+ resolution. non_glob_binding = Some ( this. new_ambiguity_binding (
361360 AmbiguityKind :: GlobVsGlob ,
362361 old_binding,
363362 binding,
364363 warn_ambiguity,
365364 ) ) ;
366365 } else if !old_binding. vis . is_at_least ( binding. vis , this. tcx ) {
367366 // We are glob-importing the same item but with greater visibility.
368- resolution. binding = Some ( binding) ;
367+ resolution. non_glob_binding = Some ( binding) ;
369368 } else if binding. is_ambiguity_recursive ( ) {
370- resolution. binding = Some ( this. new_warn_ambiguity_binding ( binding) ) ;
369+ resolution. non_glob_binding =
370+ Some ( this. new_warn_ambiguity_binding ( binding) ) ;
371371 }
372372 }
373373 ( old_glob @ true , false ) | ( old_glob @ false , true ) => {
@@ -377,38 +377,38 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
377377 && nonglob_binding. expansion != LocalExpnId :: ROOT
378378 && glob_binding. res ( ) != nonglob_binding. res ( )
379379 {
380- resolution. binding = Some ( this. new_ambiguity_binding (
380+ resolution. non_glob_binding = Some ( this. new_ambiguity_binding (
381381 AmbiguityKind :: GlobVsExpanded ,
382382 nonglob_binding,
383383 glob_binding,
384384 false ,
385385 ) ) ;
386386 } else {
387- resolution. binding = Some ( nonglob_binding) ;
387+ resolution. non_glob_binding = Some ( nonglob_binding) ;
388388 }
389389
390- if let Some ( old_shadowed_glob) = resolution. shadowed_glob {
390+ if let Some ( old_shadowed_glob) = resolution. glob_binding {
391391 assert ! ( old_shadowed_glob. is_glob_import( ) ) ;
392392 if glob_binding. res ( ) != old_shadowed_glob. res ( ) {
393- resolution. shadowed_glob = Some ( this. new_ambiguity_binding (
393+ resolution. glob_binding = Some ( this. new_ambiguity_binding (
394394 AmbiguityKind :: GlobVsGlob ,
395395 old_shadowed_glob,
396396 glob_binding,
397397 false ,
398398 ) ) ;
399399 } else if !old_shadowed_glob. vis . is_at_least ( binding. vis , this. tcx ) {
400- resolution. shadowed_glob = Some ( glob_binding) ;
400+ resolution. glob_binding = Some ( glob_binding) ;
401401 }
402402 } else {
403- resolution. shadowed_glob = Some ( glob_binding) ;
403+ resolution. glob_binding = Some ( glob_binding) ;
404404 }
405405 }
406406 ( false , false ) => {
407407 return Err ( old_binding) ;
408408 }
409409 }
410410 } else {
411- resolution. binding = Some ( binding) ;
411+ resolution. non_glob_binding = Some ( binding) ;
412412 }
413413
414414 Ok ( ( ) )
@@ -620,15 +620,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
620620 }
621621 }
622622
623+ #[ instrument( skip( self ) , level = "debug" ) ]
623624 pub ( crate ) fn check_hidden_glob_reexports (
624625 & mut self ,
625626 exported_ambiguities : FxHashSet < NameBinding < ' ra > > ,
626627 ) {
627628 for module in self . arenas . local_modules ( ) . iter ( ) {
628629 for ( key, resolution) in self . resolutions ( * module) . borrow ( ) . iter ( ) {
629630 let resolution = resolution. borrow ( ) ;
631+ debug ! ( ?resolution) ;
630632
631- let Some ( binding) = resolution. binding else { continue } ;
633+ let Some ( binding) = resolution. late_binding ( ) else { continue } ;
632634
633635 if let NameBindingKind :: Import { import, .. } = binding. kind
634636 && let Some ( ( amb_binding, _) ) = binding. ambiguity
@@ -648,7 +650,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
648650 ) ;
649651 }
650652
651- if let Some ( glob_binding) = resolution. shadowed_glob {
653+ if let Some ( glob_binding) = resolution. glob_binding {
652654 if binding. res ( ) != Res :: Err
653655 && glob_binding. res ( ) != Res :: Err
654656 && let NameBindingKind :: Import { import : glob_import, .. } =
@@ -1179,7 +1181,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11791181 return None ;
11801182 } // Never suggest the same name
11811183 match * resolution. borrow ( ) {
1182- NameResolution { binding : Some ( name_binding) , .. } => {
1184+ NameResolution { non_glob_binding : Some ( name_binding) , .. } => {
11831185 match name_binding. kind {
11841186 NameBindingKind :: Import { binding, .. } => {
11851187 match binding. kind {
0 commit comments