Skip to content

Commit bf46b9c

Browse files
committed
Explain that this is UB catching instead of malformed MIR.
1 parent 9aa4f6a commit bf46b9c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

+7
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
756756
}
757757
}
758758
StatementKind::StorageLive(local) => {
759+
// We check that the local is not live when entering a `StorageLive` for it.
760+
// Technically, violating this restriction is only UB and not actually indicative
761+
// of not well-formed MIR. This means that an optimization which turns MIR that
762+
// already has UB into MIR that fails this check is not necessarily wrong. However,
763+
// we have no such optimizations at the moment, and so we include this check anyway
764+
// to help us catch bugs. If you happen to write an optimization that might cause
765+
// this to incorrectly fire, feel free to remove this check.
759766
if self.reachable_blocks.contains(location.block) {
760767
self.storage_liveness.seek_before_primary_effect(location);
761768
let locals_with_storage = self.storage_liveness.get();

0 commit comments

Comments
 (0)