Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b1b968c

Browse files
reduce false positives of tail-expr-drop-order from consumed values
take 2
1 parent 01e2fff commit b1b968c

File tree

60 files changed

+1087
-534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1087
-534
lines changed

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
569569
| mir::StatementKind::Coverage(..)
570570
| mir::StatementKind::Intrinsic(..)
571571
| mir::StatementKind::ConstEvalCounter
572+
| mir::StatementKind::BackwardIncompatibleDropHint { .. }
572573
| mir::StatementKind::Nop => {}
573574
}
574575
}

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
651651
| StatementKind::Coverage(..)
652652
// These do not actually affect borrowck
653653
| StatementKind::ConstEvalCounter
654+
// This do not affect borrowck
655+
| StatementKind::BackwardIncompatibleDropHint { .. }
654656
| StatementKind::StorageLive(..) => {}
655657
StatementKind::StorageDead(local) => {
656658
self.access_place(

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'a, 'tcx> {
8888
| StatementKind::Nop
8989
| StatementKind::Retag { .. }
9090
| StatementKind::Deinit(..)
91+
| StatementKind::BackwardIncompatibleDropHint { .. }
9192
| StatementKind::SetDiscriminant { .. } => {
9293
bug!("Statement not allowed in this MIR phase")
9394
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13091309
| StatementKind::Coverage(..)
13101310
| StatementKind::ConstEvalCounter
13111311
| StatementKind::PlaceMention(..)
1312+
| StatementKind::BackwardIncompatibleDropHint { .. }
13121313
| StatementKind::Nop => {}
13131314
StatementKind::Deinit(..) | StatementKind::SetDiscriminant { .. } => {
13141315
bug!("Statement not allowed in this MIR phase")

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ fn codegen_stmt<'tcx>(
920920
| StatementKind::FakeRead(..)
921921
| StatementKind::Retag { .. }
922922
| StatementKind::PlaceMention(..)
923+
| StatementKind::BackwardIncompatibleDropHint { .. }
923924
| StatementKind::AscribeUserType(..) => {}
924925

925926
StatementKind::Coverage { .. } => unreachable!(),

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
578578
| StatementKind::PlaceMention(..)
579579
| StatementKind::Coverage(_)
580580
| StatementKind::ConstEvalCounter
581+
| StatementKind::BackwardIncompatibleDropHint { .. }
581582
| StatementKind::Nop => {}
582583
}
583584
}

compiler/rustc_codegen_ssa/src/mir/statement.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9292
| mir::StatementKind::AscribeUserType(..)
9393
| mir::StatementKind::ConstEvalCounter
9494
| mir::StatementKind::PlaceMention(..)
95+
| mir::StatementKind::BackwardIncompatibleDropHint { .. }
9596
| mir::StatementKind::Nop => {}
9697
}
9798
}

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
542542
| StatementKind::Coverage(..)
543543
| StatementKind::Intrinsic(..)
544544
| StatementKind::ConstEvalCounter
545+
| StatementKind::BackwardIncompatibleDropHint { .. }
545546
| StatementKind::Nop => {}
546547
}
547548
}

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
143143
// Defined to do nothing. These are added by optimization passes, to avoid changing the
144144
// size of MIR constantly.
145145
Nop => {}
146+
147+
// Only used for temporary lifetime lints
148+
BackwardIncompatibleDropHint { .. } => {}
146149
}
147150

148151
interp_ok(())

compiler/rustc_hir_analysis/src/check/region.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_index::Idx;
1717
use rustc_middle::bug;
1818
use rustc_middle::middle::region::*;
1919
use rustc_middle::ty::TyCtxt;
20+
use rustc_session::lint;
2021
use rustc_span::source_map;
2122
use 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

Comments
 (0)