Skip to content

Commit 143f5d7

Browse files
authored
Rollup merge of rust-lang#139767 - compiler-errors:www, r=oli-obk
Visit place in `BackwardIncompatibleDropHint` statement Remove a weird hack from the `LocalUpdater` where we were manually visiting the place stored in a `StatementKind::BackwardIncompatibleDropHint` because the MIR visitor impls weren't doing so. Also, clean up `BackwardIncompatibleDropHint`s in `CleanupPostBorrowck`, since they're not needed for runtime MIR.
2 parents bf49dfc + 2f96e78 commit 143f5d7

8 files changed

+19
-25
lines changed

compiler/rustc_borrowck/src/def_use.rs

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ pub(crate) fn categorize(context: PlaceContext) -> Option<DefUse> {
7777
// Debug info is neither def nor use.
7878
PlaceContext::NonUse(NonUseContext::VarDebugInfo) => None,
7979

80+
// Backwards incompatible drop hint is not a use, just a marker for linting.
81+
PlaceContext::NonUse(NonUseContext::BackwardIncompatibleDropHint) => None,
82+
8083
PlaceContext::MutatingUse(MutatingUseContext::Deinit | MutatingUseContext::SetDiscriminant) => {
8184
bug!("These statements are not allowed in this MIR phase")
8285
}

compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
12861286
error_reported
12871287
}
12881288

1289-
/// Through #123739, backward incompatible drops (BIDs) are introduced.
1289+
/// Through #123739, `BackwardIncompatibleDropHint`s (BIDs) are introduced.
12901290
/// We would like to emit lints whether borrow checking fails at these future drop locations.
12911291
#[instrument(level = "debug", skip(self, state))]
12921292
fn check_backward_incompatible_drop(

compiler/rustc_middle/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ impl Debug for Statement<'_> {
859859
BackwardIncompatibleDropHint { ref place, reason: _ } => {
860860
// For now, we don't record the reason because there is only one use case,
861861
// which is to report breaking change in drop order by Edition 2024
862-
write!(fmt, "backward incompatible drop({place:?})")
862+
write!(fmt, "BackwardIncompatibleDropHint({place:?})")
863863
}
864864
}
865865
}

compiler/rustc_middle/src/mir/visit.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,15 @@ macro_rules! make_mir_visitor {
457457
}
458458
}
459459
}
460+
StatementKind::BackwardIncompatibleDropHint { place, .. } => {
461+
self.visit_place(
462+
place,
463+
PlaceContext::NonUse(NonUseContext::BackwardIncompatibleDropHint),
464+
location
465+
);
466+
}
460467
StatementKind::ConstEvalCounter => {}
461468
StatementKind::Nop => {}
462-
StatementKind::BackwardIncompatibleDropHint { .. } => {}
463469
}
464470
}
465471

@@ -1348,6 +1354,8 @@ pub enum NonUseContext {
13481354
AscribeUserTy(ty::Variance),
13491355
/// The data of a user variable, for debug info.
13501356
VarDebugInfo,
1357+
/// A `BackwardIncompatibleDropHint` statement, meant for edition 2024 lints.
1358+
BackwardIncompatibleDropHint,
13511359
}
13521360

13531361
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -1422,7 +1430,9 @@ impl PlaceContext {
14221430
use NonUseContext::*;
14231431
match self {
14241432
PlaceContext::MutatingUse(_) => ty::Invariant,
1425-
PlaceContext::NonUse(StorageDead | StorageLive | VarDebugInfo) => ty::Invariant,
1433+
PlaceContext::NonUse(
1434+
StorageDead | StorageLive | VarDebugInfo | BackwardIncompatibleDropHint,
1435+
) => ty::Invariant,
14261436
PlaceContext::NonMutatingUse(
14271437
Inspect | Copy | Move | PlaceMention | SharedBorrow | FakeBorrow | RawBorrow
14281438
| Projection,

compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ impl<'tcx> crate::MirPass<'tcx> for CleanupPostBorrowck {
3535
// MIR building, and are not needed after InstrumentCoverage.
3636
CoverageKind::BlockMarker { .. } | CoverageKind::SpanMarker { .. },
3737
)
38-
| StatementKind::FakeRead(..) => statement.make_nop(),
38+
| StatementKind::FakeRead(..)
39+
| StatementKind::BackwardIncompatibleDropHint { .. } => statement.make_nop(),
3940
StatementKind::Assign(box (
4041
_,
4142
Rvalue::Cast(

compiler/rustc_mir_transform/src/simplify.rs

-14
Original file line numberDiff line numberDiff line change
@@ -597,20 +597,6 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater<'tcx> {
597597
self.tcx
598598
}
599599

600-
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
601-
if let StatementKind::BackwardIncompatibleDropHint { place, reason: _ } =
602-
&mut statement.kind
603-
{
604-
self.visit_local(
605-
&mut place.local,
606-
PlaceContext::MutatingUse(MutatingUseContext::Store),
607-
location,
608-
);
609-
} else {
610-
self.super_statement(statement, location);
611-
}
612-
}
613-
614600
fn visit_local(&mut self, l: &mut Local, _: PlaceContext, _: Location) {
615601
*l = self.map[*l].unwrap();
616602
}

tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-abort.mir

-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ fn method_1(_1: Guard) -> () {
7373
}
7474

7575
bb7: {
76-
backward incompatible drop(_2);
77-
backward incompatible drop(_4);
78-
backward incompatible drop(_5);
7976
goto -> bb21;
8077
}
8178

tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-unwind.mir

-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ fn method_1(_1: Guard) -> () {
7373
}
7474

7575
bb7: {
76-
backward incompatible drop(_2);
77-
backward incompatible drop(_4);
78-
backward incompatible drop(_5);
7976
goto -> bb21;
8077
}
8178

0 commit comments

Comments
 (0)