@@ -15,7 +15,7 @@ use rustc_middle::ty::fold::BottomUpFolder;
1515use rustc_middle:: ty:: subst:: Subst ;
1616use rustc_middle:: ty:: { self , InstanceDef , ParamEnv , Ty , TyCtxt , TypeFoldable , TypeVisitable } ;
1717use rustc_mir_dataflow:: impls:: MaybeStorageLive ;
18- use rustc_mir_dataflow:: storage:: always_live_locals ;
18+ use rustc_mir_dataflow:: storage:: always_storage_live_locals ;
1919use rustc_mir_dataflow:: { Analysis , ResultsCursor } ;
2020use rustc_target:: abi:: { Size , VariantIdx } ;
2121
@@ -49,7 +49,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
4949 let param_env = tcx. param_env ( def_id) ;
5050 let mir_phase = self . mir_phase ;
5151
52- let always_live_locals = always_live_locals ( body) ;
52+ let always_live_locals = always_storage_live_locals ( body) ;
5353 let storage_liveness = MaybeStorageLive :: new ( always_live_locals)
5454 . into_engine ( tcx, body)
5555 . iterate_to_fixpoint ( )
@@ -206,7 +206,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
206206 }
207207
208208 if self . reachable_blocks . contains ( location. block ) && context. is_use ( ) {
209- // Uses of locals must occur while the local's storage is allocated.
209+ // We check that the local is live whenever it is used. Technically, violating this
210+ // restriction is only UB and not actually indicative of not well-formed MIR. This means
211+ // that an optimization which turns MIR that already has UB into MIR that fails this
212+ // check is not necessarily wrong. However, we have no such optimizations at the moment,
213+ // and so we include this check anyway to help us catch bugs. If you happen to write an
214+ // optimization that might cause this to incorrectly fire, feel free to remove this
215+ // check.
210216 self . storage_liveness . seek_after_primary_effect ( location) ;
211217 let locals_with_storage = self . storage_liveness . get ( ) ;
212218 if !locals_with_storage. contains ( local) {
0 commit comments