@@ -235,21 +235,20 @@ pub(crate) struct NameResolution<'ra> {
235
235
/// Single imports that may define the name in the namespace.
236
236
/// Imports are arena-allocated, so it's ok to use pointers as keys.
237
237
pub single_imports : FxIndexSet < Import < ' ra > > ,
238
- /// The least shadowable known binding for this name, or None if there are no known bindings.
239
- pub binding : Option < NameBinding < ' ra > > ,
240
- pub shadowed_glob : Option < NameBinding < ' ra > > ,
238
+ /// The least shadowable known non-glob binding for this name, or None if there are no known bindings.
239
+ pub non_glob_binding : Option < NameBinding < ' ra > > ,
240
+ pub glob_binding : Option < NameBinding < ' ra > > ,
241
241
}
242
242
243
243
impl < ' ra > NameResolution < ' ra > {
244
244
/// Returns the binding for the name if it is known or None if it not known.
245
245
pub ( crate ) fn binding ( & self ) -> Option < NameBinding < ' ra > > {
246
- self . binding . and_then ( |binding| {
247
- if !binding. is_glob_import ( ) || self . single_imports . is_empty ( ) {
248
- Some ( binding)
249
- } else {
250
- None
251
- }
252
- } )
246
+ self . non_glob_binding
247
+ . or_else ( || if self . single_imports . is_empty ( ) { self . glob_binding } else { None } )
248
+ }
249
+
250
+ pub ( crate ) fn late_binding ( & self ) -> Option < NameBinding < ' ra > > {
251
+ self . non_glob_binding . or_else ( || self . glob_binding )
253
252
}
254
253
}
255
254
@@ -331,77 +330,79 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
331
330
self . check_reserved_macro_name ( key. ident , res) ;
332
331
self . set_binding_parent_module ( binding, module) ;
333
332
self . update_resolution ( module, key, warn_ambiguity, |this, resolution| {
334
- if let Some ( old_binding ) = resolution. binding {
335
- if res == Res :: Err && old_binding . res ( ) != Res :: Err {
333
+ if let Some ( old_non_glob_binding ) = resolution. non_glob_binding {
334
+ if res == Res :: Err && old_non_glob_binding . res ( ) != Res :: Err {
336
335
// Do not override real bindings with `Res::Err`s from error recovery.
337
336
return Ok ( ( ) ) ;
338
337
}
339
- match ( old_binding. is_glob_import ( ) , binding. is_glob_import ( ) ) {
340
- ( true , true ) => {
341
- // FIXME: remove `!binding.is_ambiguity_recursive()` after delete the warning ambiguity.
342
- if !binding. is_ambiguity_recursive ( )
343
- && let NameBindingKind :: Import { import : old_import, .. } =
344
- old_binding. kind
345
- && let NameBindingKind :: Import { import, .. } = binding. kind
346
- && old_import == import
347
- {
348
- // We should replace the `old_binding` with `binding` regardless
349
- // of whether they has same resolution or not when they are
350
- // imported from the same glob-import statement.
351
- resolution. binding = Some ( binding) ;
352
- } else if res != old_binding. res ( ) {
353
- resolution. binding = Some ( this. new_ambiguity_binding (
354
- AmbiguityKind :: GlobVsGlob ,
355
- old_binding,
356
- binding,
357
- warn_ambiguity,
358
- ) ) ;
359
- } else if !old_binding. vis . is_at_least ( binding. vis , this. tcx ) {
360
- // We are glob-importing the same item but with greater visibility.
361
- resolution. binding = Some ( binding) ;
362
- } else if binding. is_ambiguity_recursive ( ) {
363
- resolution. binding = Some ( this. new_warn_ambiguity_binding ( binding) ) ;
364
- }
338
+
339
+ if binding. is_glob_import ( ) {
340
+ let ( glob_binding, nonglob_binding) = ( binding, old_non_glob_binding) ;
341
+
342
+ if key. ns == MacroNS
343
+ && nonglob_binding. expansion != LocalExpnId :: ROOT
344
+ && glob_binding. res ( ) != nonglob_binding. res ( )
345
+ {
346
+ resolution. non_glob_binding = Some ( this. new_ambiguity_binding (
347
+ AmbiguityKind :: GlobVsExpanded ,
348
+ nonglob_binding,
349
+ glob_binding,
350
+ false ,
351
+ ) ) ;
365
352
}
366
- ( old_glob @ true , false ) | ( old_glob @ false , true ) => {
367
- let ( glob_binding, nonglob_binding) =
368
- if old_glob { ( old_binding, binding) } else { ( binding, old_binding) } ;
369
- if key. ns == MacroNS
370
- && nonglob_binding. expansion != LocalExpnId :: ROOT
371
- && glob_binding. res ( ) != nonglob_binding. res ( )
372
- {
373
- resolution. binding = Some ( this. new_ambiguity_binding (
374
- AmbiguityKind :: GlobVsExpanded ,
375
- nonglob_binding,
353
+
354
+ if let Some ( old_glob) = resolution. glob_binding {
355
+ if glob_binding. res ( ) != old_glob. res ( ) {
356
+ resolution. glob_binding = Some ( this. new_ambiguity_binding (
357
+ AmbiguityKind :: GlobVsGlob ,
358
+ old_glob,
376
359
glob_binding,
377
- false ,
360
+ warn_ambiguity ,
378
361
) ) ;
379
- } else {
380
- resolution. binding = Some ( nonglob_binding) ;
381
- }
382
-
383
- if let Some ( old_shadowed_glob) = resolution. shadowed_glob {
384
- assert ! ( old_shadowed_glob. is_glob_import( ) ) ;
385
- if glob_binding. res ( ) != old_shadowed_glob. res ( ) {
386
- resolution. shadowed_glob = Some ( this. new_ambiguity_binding (
387
- AmbiguityKind :: GlobVsGlob ,
388
- old_shadowed_glob,
389
- glob_binding,
390
- false ,
391
- ) ) ;
392
- } else if !old_shadowed_glob. vis . is_at_least ( binding. vis , this. tcx ) {
393
- resolution. shadowed_glob = Some ( glob_binding) ;
394
- }
395
- } else {
396
- resolution. shadowed_glob = Some ( glob_binding) ;
362
+ } else if !old_glob. vis . is_at_least ( glob_binding. vis , this. tcx ) {
363
+ resolution. glob_binding = Some ( glob_binding) ;
397
364
}
365
+ } else {
366
+ resolution. glob_binding = Some ( glob_binding) ;
398
367
}
399
- ( false , false ) => {
400
- return Err ( old_binding) ;
368
+ } else {
369
+ return Err ( old_non_glob_binding) ;
370
+ }
371
+ } else if let Some ( old_glob_binding) = resolution. glob_binding {
372
+ if binding. is_glob_import ( ) {
373
+ // FIXME: remove `!binding.is_ambiguity_recursive()` after delete the warning ambiguity.
374
+ if !binding. is_ambiguity_recursive ( )
375
+ && let NameBindingKind :: Import { import : old_import, .. } =
376
+ old_glob_binding. kind
377
+ && let NameBindingKind :: Import { import, .. } = binding. kind
378
+ && old_import == import
379
+ {
380
+ // We should replace the `old_binding` with `binding` regardless
381
+ // of whether they has same resolution or not when they are
382
+ // imported from the same glob-import statement.
383
+ resolution. glob_binding = Some ( binding) ;
384
+ } else if res != old_glob_binding. res ( ) {
385
+ resolution. glob_binding = Some ( this. new_ambiguity_binding (
386
+ AmbiguityKind :: GlobVsGlob ,
387
+ old_glob_binding,
388
+ binding,
389
+ warn_ambiguity,
390
+ ) ) ;
391
+ } else if !old_glob_binding. vis . is_at_least ( binding. vis , this. tcx ) {
392
+ // We are glob-importing the same item but with greater visibility.
393
+ resolution. glob_binding = Some ( binding) ;
394
+ } else if binding. is_ambiguity_recursive ( ) {
395
+ resolution. glob_binding = Some ( this. new_warn_ambiguity_binding ( binding) ) ;
401
396
}
397
+ } else {
398
+ resolution. non_glob_binding = Some ( binding) ;
402
399
}
403
400
} else {
404
- resolution. binding = Some ( binding) ;
401
+ if binding. is_glob_import ( ) {
402
+ resolution. glob_binding = Some ( binding) ;
403
+ } else {
404
+ resolution. non_glob_binding = Some ( binding) ;
405
+ }
405
406
}
406
407
407
408
Ok ( ( ) )
@@ -619,7 +620,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
619
620
for ( key, resolution) in self . resolutions ( * module) . borrow ( ) . iter ( ) {
620
621
let resolution = resolution. borrow ( ) ;
621
622
622
- let Some ( binding) = resolution. binding else { continue } ;
623
+ let Some ( binding) = resolution. non_glob_binding else { continue } ;
623
624
624
625
if let NameBindingKind :: Import { import, .. } = binding. kind
625
626
&& let Some ( ( amb_binding, _) ) = binding. ambiguity
@@ -639,7 +640,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
639
640
) ;
640
641
}
641
642
642
- if let Some ( glob_binding) = resolution. shadowed_glob {
643
+ if let Some ( glob_binding) = resolution. glob_binding {
643
644
if binding. res ( ) != Res :: Err
644
645
&& glob_binding. res ( ) != Res :: Err
645
646
&& let NameBindingKind :: Import { import : glob_import, .. } =
@@ -1162,7 +1163,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1162
1163
return None ;
1163
1164
} // Never suggest the same name
1164
1165
match * resolution. borrow ( ) {
1165
- NameResolution { binding : Some ( name_binding) , .. } => {
1166
+ NameResolution { non_glob_binding : Some ( name_binding) , .. } => {
1166
1167
match name_binding. kind {
1167
1168
NameBindingKind :: Import { binding, .. } => {
1168
1169
match binding. kind {
0 commit comments