Skip to content

Commit d583342

Browse files
committed
Auto merge of rust-lang#102256 - cjgillot:let-under, r=lcnr
Introduce a no-op `PlaceMention` statement for `let _ =`. Fixes rust-lang#54003 Fixes rust-lang#80059 Split from rust-lang#101500 This PR introduces a new `PlaceMention` statement dedicated to matches that neither introduce bindings nor ascribe types. Without this, all traces of the match would vanish from MIR, making it impossible to diagnose unsafety or use in rust-lang#101500. This allows to mark `let _ = <unsafe union access or dereference>` as requiring an unsafe block. Nominating for lang team, as this introduces an extra error.
2 parents 104f430 + 684de04 commit d583342

Some content is hidden

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

48 files changed

+271
-19
lines changed

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
390390
| mir::StatementKind::Deinit(..)
391391
| mir::StatementKind::StorageLive(..)
392392
| mir::StatementKind::Retag { .. }
393+
| mir::StatementKind::PlaceMention(..)
393394
| mir::StatementKind::AscribeUserType(..)
394395
| mir::StatementKind::Coverage(..)
395396
| mir::StatementKind::Intrinsic(..)

compiler/rustc_borrowck/src/def_use.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
7272
PlaceContext::MutatingUse(MutatingUseContext::Drop) =>
7373
Some(DefUse::Drop),
7474

75+
// This statement exists to help unsafeck. It does not require the place to be live.
76+
PlaceContext::NonUse(NonUseContext::PlaceMention) => None,
7577
// Debug info is neither def nor use.
7678
PlaceContext::NonUse(NonUseContext::VarDebugInfo) => None,
7779

compiler/rustc_borrowck/src/invalidation.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
7979
}
8080
// Only relevant for mir typeck
8181
StatementKind::AscribeUserType(..)
82+
// Only relevant for unsafeck
83+
| StatementKind::PlaceMention(..)
8284
// Doesn't have any language semantics
8385
| StatementKind::Coverage(..)
8486
// Does not actually affect borrowck

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,8 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
690690
}
691691
// Only relevant for mir typeck
692692
StatementKind::AscribeUserType(..)
693+
// Only relevant for unsafeck
694+
| StatementKind::PlaceMention(..)
693695
// Doesn't have any language semantics
694696
| StatementKind::Coverage(..)
695697
// These do not actually affect borrowck

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,9 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
772772

773773
match context {
774774
PlaceContext::MutatingUse(_) => ty::Invariant,
775-
PlaceContext::NonUse(StorageDead | StorageLive | VarDebugInfo) => ty::Invariant,
775+
PlaceContext::NonUse(StorageDead | StorageLive | PlaceMention | VarDebugInfo) => {
776+
ty::Invariant
777+
}
776778
PlaceContext::NonMutatingUse(
777779
Inspect | Copy | Move | SharedBorrow | ShallowBorrow | UniqueBorrow | AddressOf
778780
| Projection,
@@ -1282,6 +1284,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12821284
| StatementKind::Retag { .. }
12831285
| StatementKind::Coverage(..)
12841286
| StatementKind::ConstEvalCounter
1287+
| StatementKind::PlaceMention(..)
12851288
| StatementKind::Nop => {}
12861289
StatementKind::Deinit(..) | StatementKind::SetDiscriminant { .. } => {
12871290
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
@@ -819,6 +819,7 @@ fn codegen_stmt<'tcx>(
819819
| StatementKind::Nop
820820
| StatementKind::FakeRead(..)
821821
| StatementKind::Retag { .. }
822+
| StatementKind::PlaceMention(..)
822823
| StatementKind::AscribeUserType(..) => {}
823824

824825
StatementKind::Coverage { .. } => fx.tcx.sess.fatal("-Zcoverage is unimplemented"),

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
529529
| StatementKind::StorageDead(_)
530530
| StatementKind::Retag(_, _)
531531
| StatementKind::AscribeUserType(_, _)
532+
| StatementKind::PlaceMention(..)
532533
| StatementKind::Coverage(_)
533534
| StatementKind::ConstEvalCounter
534535
| StatementKind::Nop => {}

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::Retag { .. }
9393
| mir::StatementKind::AscribeUserType(..)
9494
| mir::StatementKind::ConstEvalCounter
95+
| mir::StatementKind::PlaceMention(..)
9596
| mir::StatementKind::Nop => {}
9697
}
9798
}

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
114114
Intrinsic(box intrinsic) => self.emulate_nondiverging_intrinsic(intrinsic)?,
115115

116116
// Statements we do not track.
117-
AscribeUserType(..) => {}
117+
PlaceMention(..) | AscribeUserType(..) => {}
118118

119119
// Currently, Miri discards Coverage statements. Coverage statements are only injected
120120
// via an optional compile time MIR pass and have no side effects. Since Coverage

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
690690
| StatementKind::StorageLive(_)
691691
| StatementKind::StorageDead(_)
692692
| StatementKind::Retag { .. }
693+
| StatementKind::PlaceMention(..)
693694
| StatementKind::AscribeUserType(..)
694695
| StatementKind::Coverage(..)
695696
| StatementKind::Intrinsic(..)

0 commit comments

Comments
 (0)