@@ -429,6 +429,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
429429 // to detect potential ambiguities.
430430 let mut innermost_result: Option < ( NameBinding < ' _ > , Flags ) > = None ;
431431 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+ }
432436
433437 // Go through all the scopes and try to resolve the name.
434438 let break_result = self . visit_scopes (
@@ -494,13 +498,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
494498 _ => Err ( Determinacy :: Determined ) ,
495499 } ,
496500 Scope :: Module ( module, derive_fallback_lint_id) => {
497- let ( adjusted_parent_scope, finalize ) =
501+ let ( adjusted_parent_scope, adjusted_finalize ) =
498502 if matches ! ( scope_set, ScopeSet :: ModuleAndExternPrelude ( ..) ) {
499- ( parent_scope, finalize )
503+ ( parent_scope, finalize_scope ! ( ) )
500504 } else {
501505 (
502506 & ParentScope { module, ..* parent_scope } ,
503- finalize . map ( |f| Finalize { used : Used :: Scope , ..f } ) ,
507+ finalize_scope ! ( ) . map ( |f| Finalize { used : Used :: Scope , ..f } ) ,
504508 )
505509 } ;
506510 let binding = this. reborrow ( ) . resolve_ident_in_module_unadjusted (
@@ -513,7 +517,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
513517 } else {
514518 Shadowing :: Restricted
515519 } ,
516- finalize ,
520+ adjusted_finalize ,
517521 ignore_binding,
518522 ignore_import,
519523 ) ;
@@ -562,7 +566,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
562566 None => Err ( Determinacy :: Determined ) ,
563567 } ,
564568 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+ {
566571 Some ( binding) => Ok ( ( binding, Flags :: empty ( ) ) ) ,
567572 None => Err ( Determinacy :: determined (
568573 this. graph_root . unexpanded_invocations . borrow ( ) . is_empty ( ) ,
@@ -599,8 +604,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
599604 if matches ! ( ident. name, sym:: f16)
600605 && !this. tcx . features ( ) . f16 ( )
601606 && !ident. span . allows_unstable ( sym:: f16)
602- && finalize. is_some ( )
603- && innermost_result. is_none ( )
607+ && finalize_scope ! ( ) . is_some ( )
604608 {
605609 feature_err (
606610 this. tcx . sess ,
@@ -613,8 +617,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
613617 if matches ! ( ident. name, sym:: f128)
614618 && !this. tcx . features ( ) . f128 ( )
615619 && !ident. span . allows_unstable ( sym:: f128)
616- && finalize. is_some ( )
617- && innermost_result. is_none ( )
620+ && finalize_scope ! ( ) . is_some ( )
618621 {
619622 feature_err (
620623 this. tcx . sess ,
0 commit comments