@@ -3,9 +3,10 @@ use crate::borrow_check::nll::type_check::liveness::local_use_map::LocalUseMap;
33use crate :: borrow_check:: nll:: type_check:: liveness:: polonius;
44use crate :: borrow_check:: nll:: type_check:: NormalizeLocation ;
55use crate :: borrow_check:: nll:: type_check:: TypeChecker ;
6+ use crate :: dataflow:: generic:: ResultsCursor ;
67use crate :: dataflow:: indexes:: MovePathIndex ;
7- use crate :: dataflow:: move_paths:: MoveData ;
8- use crate :: dataflow:: { FlowAtLocation , FlowsAtLocation , MaybeInitializedPlaces } ;
8+ use crate :: dataflow:: move_paths:: { HasMoveData , MoveData } ;
9+ use crate :: dataflow:: MaybeInitializedPlaces ;
910use rustc:: infer:: canonical:: QueryRegionConstraints ;
1011use rustc:: mir:: { BasicBlock , Body , ConstraintCategory , Local , Location } ;
1112use rustc:: traits:: query:: dropck_outlives:: DropckOutlivesResult ;
@@ -34,7 +35,7 @@ pub(super) fn trace(
3435 typeck : & mut TypeChecker < ' _ , ' tcx > ,
3536 body : & Body < ' tcx > ,
3637 elements : & Rc < RegionValueElements > ,
37- flow_inits : & mut FlowAtLocation < ' tcx , MaybeInitializedPlaces < ' _ , ' tcx > > ,
38+ flow_inits : & mut ResultsCursor < ' mir , ' tcx , MaybeInitializedPlaces < ' mir , ' tcx > > ,
3839 move_data : & MoveData < ' tcx > ,
3940 live_locals : Vec < Local > ,
4041 polonius_drop_used : Option < Vec < ( Local , Location ) > > ,
@@ -81,7 +82,7 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
8182
8283 /// Results of dataflow tracking which variables (and paths) have been
8384 /// initialized.
84- flow_inits : & ' me mut FlowAtLocation < ' tcx , MaybeInitializedPlaces < ' flow , ' tcx > > ,
85+ flow_inits : & ' me mut ResultsCursor < ' flow , ' tcx , MaybeInitializedPlaces < ' flow , ' tcx > > ,
8586
8687 /// Index indicating where each variable is assigned, used, or
8788 /// dropped.
@@ -389,23 +390,26 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
389390}
390391
391392impl LivenessContext < ' _ , ' _ , ' _ , ' tcx > {
393+ /// Returns `true` if the local variable (or some part of it) is initialized at the current
394+ /// cursor position. Callers should call one of the `seek` methods immediately before to point
395+ /// the cursor to the desired location.
396+ fn initialized_at_curr_loc ( & self , mpi : MovePathIndex ) -> bool {
397+ let state = self . flow_inits . get ( ) ;
398+ if state. contains ( mpi) {
399+ return true ;
400+ }
401+
402+ let move_paths = & self . flow_inits . analysis ( ) . move_data ( ) . move_paths ;
403+ move_paths[ mpi] . find_child ( & move_paths, |mpi| state. contains ( mpi) ) . is_some ( )
404+ }
405+
392406 /// Returns `true` if the local variable (or some part of it) is initialized in
393407 /// the terminator of `block`. We need to check this to determine if a
394408 /// DROP of some local variable will have an effect -- note that
395409 /// drops, as they may unwind, are always terminators.
396410 fn initialized_at_terminator ( & mut self , block : BasicBlock , mpi : MovePathIndex ) -> bool {
397- // Compute the set of initialized paths at terminator of block
398- // by resetting to the start of the block and then applying
399- // the effects of all statements. This is the only way to get
400- // "just ahead" of a terminator.
401- self . flow_inits . reset_to_entry_of ( block) ;
402- for statement_index in 0 ..self . body [ block] . statements . len ( ) {
403- let location = Location { block, statement_index } ;
404- self . flow_inits . reconstruct_statement_effect ( location) ;
405- self . flow_inits . apply_local_effect ( location) ;
406- }
407-
408- self . flow_inits . has_any_child_of ( mpi) . is_some ( )
411+ self . flow_inits . seek_before ( self . body . terminator_loc ( block) ) ;
412+ self . initialized_at_curr_loc ( mpi)
409413 }
410414
411415 /// Returns `true` if the path `mpi` (or some part of it) is initialized at
@@ -414,8 +418,8 @@ impl LivenessContext<'_, '_, '_, 'tcx> {
414418 /// **Warning:** Does not account for the result of `Call`
415419 /// instructions.
416420 fn initialized_at_exit ( & mut self , block : BasicBlock , mpi : MovePathIndex ) -> bool {
417- self . flow_inits . reset_to_exit_of ( block) ;
418- self . flow_inits . has_any_child_of ( mpi) . is_some ( )
421+ self . flow_inits . seek_after ( self . body . terminator_loc ( block) ) ;
422+ self . initialized_at_curr_loc ( mpi)
419423 }
420424
421425 /// Stores the result that all regions in `value` are live for the
0 commit comments