@@ -429,6 +429,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
429
429
// to detect potential ambiguities.
430
430
let mut innermost_result: Option < ( NameBinding < ' _ > , Flags ) > = None ;
431
431
let mut determinacy = Determinacy :: Determined ;
432
+ // Shadowed bindings don't need to be marked as used or non-speculatively loaded.
433
+ macro finalize_scope ( ) {
434
+ if innermost_result. is_none ( ) { finalize } else { None }
435
+ }
432
436
433
437
// Go through all the scopes and try to resolve the name.
434
438
let break_result = self . visit_scopes (
@@ -494,13 +498,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
494
498
_ => Err ( Determinacy :: Determined ) ,
495
499
} ,
496
500
Scope :: Module ( module, derive_fallback_lint_id) => {
497
- let ( adjusted_parent_scope, finalize ) =
501
+ let ( adjusted_parent_scope, adjusted_finalize ) =
498
502
if matches ! ( scope_set, ScopeSet :: ModuleAndExternPrelude ( ..) ) {
499
- ( parent_scope, finalize )
503
+ ( parent_scope, finalize_scope ! ( ) )
500
504
} else {
501
505
(
502
506
& ParentScope { module, ..* parent_scope } ,
503
- finalize . map ( |f| Finalize { used : Used :: Scope , ..f } ) ,
507
+ finalize_scope ! ( ) . map ( |f| Finalize { used : Used :: Scope , ..f } ) ,
504
508
)
505
509
} ;
506
510
let binding = this. reborrow ( ) . resolve_ident_in_module_unadjusted (
@@ -513,7 +517,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
513
517
} else {
514
518
Shadowing :: Restricted
515
519
} ,
516
- finalize ,
520
+ adjusted_finalize ,
517
521
ignore_binding,
518
522
ignore_import,
519
523
) ;
@@ -562,7 +566,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
562
566
None => Err ( Determinacy :: Determined ) ,
563
567
} ,
564
568
Scope :: ExternPrelude => {
565
- match this. reborrow ( ) . extern_prelude_get ( ident, finalize. is_some ( ) ) {
569
+ match this. reborrow ( ) . extern_prelude_get ( ident, finalize_scope ! ( ) . is_some ( ) )
570
+ {
566
571
Some ( binding) => Ok ( ( binding, Flags :: empty ( ) ) ) ,
567
572
None => Err ( Determinacy :: determined (
568
573
this. graph_root . unexpanded_invocations . borrow ( ) . is_empty ( ) ,
@@ -599,8 +604,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
599
604
if matches ! ( ident. name, sym:: f16)
600
605
&& !this. tcx . features ( ) . f16 ( )
601
606
&& !ident. span . allows_unstable ( sym:: f16)
602
- && finalize. is_some ( )
603
- && innermost_result. is_none ( )
607
+ && finalize_scope ! ( ) . is_some ( )
604
608
{
605
609
feature_err (
606
610
this. tcx . sess ,
@@ -613,8 +617,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
613
617
if matches ! ( ident. name, sym:: f128)
614
618
&& !this. tcx . features ( ) . f128 ( )
615
619
&& !ident. span . allows_unstable ( sym:: f128)
616
- && finalize. is_some ( )
617
- && innermost_result. is_none ( )
620
+ && finalize_scope ! ( ) . is_some ( )
618
621
{
619
622
feature_err (
620
623
this. tcx . sess ,
0 commit comments