Skip to content

Commit f74695b

Browse files
committed
Document handling of StorageDead.
1 parent e11e408 commit f74695b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

+15
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,21 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
889889
StatementKind::StorageLive(local) => {
890890
Self::remove_const(&mut self.ecx, local);
891891
}
892+
// We do not need to mark dead locals as such. For `FullConstProp` locals,
893+
// this allows to propagate the single assigned value in this case:
894+
// ```
895+
// let x = SOME_CONST;
896+
// if a {
897+
// f(copy x);
898+
// StorageDead(x);
899+
// } else {
900+
// g(copy x);
901+
// StorageDead(x);
902+
// }
903+
// ```
904+
//
905+
// This may propagate a constant where the local would be uninit or dead.
906+
// In both cases, this does not matter, as those reads would be UB anyway.
892907
_ => {}
893908
}
894909
}

0 commit comments

Comments
 (0)