Skip to content

Commit 00e64ba

Browse files
committed
Validate removal of AscribeUserType, FakeRead, and Shallow borrow
Those statements are removed by CleanupNonCodegenStatements pass in drop lowering phase, and should not occur afterwards.
1 parent e2be5f5 commit 00e64ba

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

compiler/rustc_mir/src/transform/validate.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use super::{MirPass, MirSource};
44
use rustc_middle::mir::visit::Visitor;
55
use rustc_middle::{
66
mir::{
7-
AggregateKind, BasicBlock, Body, Location, MirPhase, Operand, Rvalue, Statement,
8-
StatementKind, Terminator, TerminatorKind,
7+
AggregateKind, BasicBlock, Body, BorrowKind, Location, MirPhase, Operand, Rvalue,
8+
Statement, StatementKind, Terminator, TerminatorKind,
99
},
1010
ty::{
1111
self,
@@ -274,9 +274,33 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
274274
)
275275
}
276276
}
277+
Rvalue::Ref(_, BorrowKind::Shallow, _) => {
278+
if self.mir_phase > MirPhase::DropLowering {
279+
self.fail(
280+
location,
281+
"`Assign` statement with a `Shallow` borrow should have been removed after drop lowering phase",
282+
);
283+
}
284+
}
277285
_ => {}
278286
}
279287
}
288+
StatementKind::AscribeUserType(..) => {
289+
if self.mir_phase > MirPhase::DropLowering {
290+
self.fail(
291+
location,
292+
"`AscribeUserType` should have been removed after drop lowering phase",
293+
);
294+
}
295+
}
296+
StatementKind::FakeRead(..) => {
297+
if self.mir_phase > MirPhase::DropLowering {
298+
self.fail(
299+
location,
300+
"`FakeRead` should have been removed after drop lowering phase",
301+
);
302+
}
303+
}
280304
_ => {}
281305
}
282306
}

0 commit comments

Comments
 (0)