Skip to content

Commit fe2b229

Browse files
committed
Address unwind drop order review feedback
1 parent 1d981d0 commit fe2b229

75 files changed

Lines changed: 932 additions & 350 deletions

File tree

Some content is hidden

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

compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'a, 'tcx> {
7070
// Doesn't have any language semantics
7171
| StatementKind::Coverage(..)
7272
// Does not actually affect borrowck
73-
| StatementKind::StorageLive(..) => {}
73+
| StatementKind::StorageLive(..)
74+
// Future-compatibility drop hints are lint markers, not loan invalidations.
75+
| StatementKind::BackwardIncompatibleDropHint { .. } => {}
7476
StatementKind::StorageDead(local) => {
7577
self.access_place(
7678
location,
@@ -81,7 +83,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'a, 'tcx> {
8183
}
8284
StatementKind::ConstEvalCounter
8385
| StatementKind::Nop
84-
| StatementKind::BackwardIncompatibleDropHint { .. }
8586
| StatementKind::SetDiscriminant { .. } => {
8687
bug!("Statement not allowed in this MIR phase")
8788
}

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -879,10 +879,8 @@ impl Debug for StatementKind<'_> {
879879
Intrinsic(ref intrinsic) => write!(fmt, "{intrinsic}"),
880880
ConstEvalCounter => write!(fmt, "ConstEvalCounter"),
881881
Nop => write!(fmt, "nop"),
882-
BackwardIncompatibleDropHint { ref place, reason: _ } => {
883-
// The reason is intentionally omitted to keep MIR diffs stable
884-
// across future-compatibility lint implementation details.
885-
write!(fmt, "BackwardIncompatibleDropHint({place:?})")
882+
BackwardIncompatibleDropHint { ref place, reason } => {
883+
write!(fmt, "BackwardIncompatibleDropHint({place:?}, {reason:?})")
886884
}
887885
}
888886
}

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ pub enum StatementKind<'tcx> {
445445
/// Marker statement indicating where `place` would be dropped.
446446
/// This is semantically equivalent to `Nop`, so codegen and MIRI should interpret this
447447
/// statement as such.
448-
/// The only use case of this statement is for linting in MIR to detect temporary lifetime
449-
/// changes.
448+
/// The only use case of this statement is for MIR future-compatibility linting.
450449
BackwardIncompatibleDropHint {
451450
/// Place to drop
452451
place: Box<Place<'tcx>>,

compiler/rustc_mir_build/src/builder/scope.rs

Lines changed: 54 additions & 135 deletions
Large diffs are not rendered by default.

compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
207207
let mut ty_dropped_components = UnordMap::default();
208208
for (block, data) in body.basic_blocks.iter_enumerated() {
209209
for (statement_index, stmt) in data.statements.iter().enumerate() {
210-
if let StatementKind::BackwardIncompatibleDropHint { place, reason: _ } = &stmt.kind {
210+
if let StatementKind::BackwardIncompatibleDropHint {
211+
place,
212+
reason: mir::BackwardIncompatibleDropReason::Edition2024,
213+
} = &stmt.kind
214+
{
211215
let ty = place.ty(body, tcx).ty;
212216
if ty_dropped_components
213217
.entry(ty)

src/tools/miri/tests/fail/tail_calls/dangling-local-var.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ LL | let local = 0;
1414
help: ALLOC was deallocated here:
1515
--> tests/fail/tail_calls/dangling-local-var.rs:LL:CC
1616
|
17-
LL | let _val = unsafe { *x };
18-
| ^^^^
17+
LL | become g(ptr)
18+
| ^
1919
= note: stack backtrace:
2020
0: g
2121
at tests/fail/tail_calls/dangling-local-var.rs:LL:CC

tests/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ fn main() -> () {
7373
}
7474

7575
bb6 (cleanup): {
76-
StorageDead(_6);
76+
BackwardIncompatibleDropHint(_6, UnwindStorageDead);
7777
drop(_5) -> [return: bb7, unwind terminate(cleanup)];
7878
}
7979

8080
bb7 (cleanup): {
81-
StorageDead(_5);
81+
BackwardIncompatibleDropHint(_5, UnwindStorageDead);
8282
drop(_4) -> [return: bb8, unwind terminate(cleanup)];
8383
}
8484

8585
bb8 (cleanup): {
86-
StorageDead(_4);
87-
StorageDead(_2);
88-
StorageDead(_1);
86+
BackwardIncompatibleDropHint(_4, UnwindStorageDead);
87+
BackwardIncompatibleDropHint(_2, UnwindStorageDead);
88+
BackwardIncompatibleDropHint(_1, UnwindStorageDead);
8989
resume;
9090
}
9191
}

tests/mir-opt/building/eq_never_type._f.built.after.mir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ fn _f(_1: !, _2: !) -> () {
4848
}
4949

5050
bb5 (cleanup): {
51+
BackwardIncompatibleDropHint(_7, UnwindStorageDead);
52+
BackwardIncompatibleDropHint(_5, UnwindStorageDead);
53+
BackwardIncompatibleDropHint(_8, UnwindStorageDead);
54+
BackwardIncompatibleDropHint(_4, UnwindStorageDead);
5155
resume;
5256
}
5357
}

tests/mir-opt/building/index_array_and_slice.index_array.built.after.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ fn index_array(_1: &[i32; 7], _2: usize) -> &i32 {
2626
}
2727

2828
bb2 (cleanup): {
29+
BackwardIncompatibleDropHint(_4, UnwindStorageDead);
30+
BackwardIncompatibleDropHint(_3, UnwindStorageDead);
2931
resume;
3032
}
3133
}

tests/mir-opt/building/index_array_and_slice.index_const_generic_array.built.after.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ fn index_const_generic_array(_1: &[i32; N], _2: usize) -> &i32 {
2626
}
2727

2828
bb2 (cleanup): {
29+
BackwardIncompatibleDropHint(_4, UnwindStorageDead);
30+
BackwardIncompatibleDropHint(_3, UnwindStorageDead);
2931
resume;
3032
}
3133
}

0 commit comments

Comments
 (0)