@@ -15,7 +15,7 @@ use rustc_middle::ty::fold::BottomUpFolder;
15
15
use rustc_middle:: ty:: subst:: Subst ;
16
16
use rustc_middle:: ty:: { self , InstanceDef , ParamEnv , Ty , TyCtxt , TypeFoldable , TypeVisitable } ;
17
17
use rustc_mir_dataflow:: impls:: MaybeStorageLive ;
18
- use rustc_mir_dataflow:: storage:: always_live_locals ;
18
+ use rustc_mir_dataflow:: storage:: always_storage_live_locals ;
19
19
use rustc_mir_dataflow:: { Analysis , ResultsCursor } ;
20
20
use rustc_target:: abi:: { Size , VariantIdx } ;
21
21
@@ -49,7 +49,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
49
49
let param_env = tcx. param_env ( def_id) ;
50
50
let mir_phase = self . mir_phase ;
51
51
52
- let always_live_locals = always_live_locals ( body) ;
52
+ let always_live_locals = always_storage_live_locals ( body) ;
53
53
let storage_liveness = MaybeStorageLive :: new ( always_live_locals)
54
54
. into_engine ( tcx, body)
55
55
. iterate_to_fixpoint ( )
@@ -206,7 +206,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
206
206
}
207
207
208
208
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.
210
216
self . storage_liveness . seek_after_primary_effect ( location) ;
211
217
let locals_with_storage = self . storage_liveness . get ( ) ;
212
218
if !locals_with_storage. contains ( local) {
0 commit comments