@@ -17,6 +17,7 @@ use rustc_index::Idx;
1717use rustc_middle:: bug;
1818use rustc_middle:: middle:: region:: * ;
1919use rustc_middle:: ty:: TyCtxt ;
20+ use rustc_session:: lint;
2021use rustc_span:: source_map;
2122use tracing:: debug;
2223
@@ -167,10 +168,24 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
167168 }
168169 }
169170 if let Some ( tail_expr) = blk. expr {
170- if visitor. tcx . features ( ) . shorter_tail_lifetimes
171- && blk. span . edition ( ) . at_least_rust_2024 ( )
171+ let local_id = tail_expr. hir_id . local_id ;
172+ let edition = blk. span . edition ( ) ;
173+ if visitor. tcx . features ( ) . shorter_tail_lifetimes && edition. at_least_rust_2024 ( ) {
174+ visitor. terminating_scopes . insert ( local_id) ;
175+ } else if edition < lint:: Edition :: Edition2024
176+ && !matches ! (
177+ visitor. tcx. lint_level_at_node( lint:: builtin:: TAIL_EXPR_DROP_ORDER , blk. hir_id) ,
178+ ( lint:: Level :: Allow , _)
179+ )
172180 {
173- visitor. terminating_scopes . insert ( tail_expr. hir_id . local_id ) ;
181+ // If this temporary scope will be changing once the codebase adopts Rust 2024,
182+ // and we are linting about possible semantic changes that would result,
183+ // then record this node-id in the field `backwards_incompatible_scope`
184+ // for future reference.
185+ visitor
186+ . scope_tree
187+ . backwards_incompatible_scope
188+ . insert ( local_id, Scope { id : local_id, data : ScopeData :: Node } ) ;
174189 }
175190 visitor. visit_expr ( tail_expr) ;
176191 }
0 commit comments