@@ -39,17 +39,15 @@ use crate::type_check::{NormalizeLocation, TypeChecker};
3939/// this respects `#[may_dangle]` annotations).
4040pub ( super ) fn trace < ' a , ' tcx > (
4141 typeck : & mut TypeChecker < ' _ , ' tcx > ,
42- body : & Body < ' tcx > ,
4342 location_map : & DenseLocationMap ,
4443 flow_inits : ResultsCursor < ' a , ' tcx , MaybeInitializedPlaces < ' a , ' tcx > > ,
4544 move_data : & MoveData < ' tcx > ,
4645 relevant_live_locals : Vec < Local > ,
4746 boring_locals : Vec < Local > ,
4847) {
49- let local_use_map = & LocalUseMap :: build ( & relevant_live_locals, location_map, body) ;
48+ let local_use_map = & LocalUseMap :: build ( & relevant_live_locals, location_map, typeck . body ) ;
5049 let cx = LivenessContext {
5150 typeck,
52- body,
5351 flow_inits,
5452 location_map,
5553 local_use_map,
@@ -69,14 +67,13 @@ pub(super) fn trace<'a, 'tcx>(
6967/// Contextual state for the type-liveness coroutine.
7068struct LivenessContext < ' a , ' typeck , ' b , ' tcx > {
7169 /// Current type-checker, giving us our inference context etc.
70+ ///
71+ /// This also stores the body we're currently analyzing.
7272 typeck : & ' a mut TypeChecker < ' typeck , ' tcx > ,
7373
7474 /// Defines the `PointIndex` mapping
7575 location_map : & ' a DenseLocationMap ,
7676
77- /// MIR we are analyzing.
78- body : & ' a Body < ' tcx > ,
79-
8077 /// Mapping to/from the various indices used for initialization tracking.
8178 move_data : & ' a MoveData < ' tcx > ,
8279
@@ -139,7 +136,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
139136 self . compute_use_live_points_for ( local) ;
140137 self . compute_drop_live_points_for ( local) ;
141138
142- let local_ty = self . cx . body . local_decls [ local] . ty ;
139+ let local_ty = self . cx . body ( ) . local_decls [ local] . ty ;
143140
144141 if !self . use_live_at . is_empty ( ) {
145142 self . cx . add_use_live_facts_for ( local_ty, & self . use_live_at ) ;
@@ -164,16 +161,16 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
164161 /// and can therefore safely be dropped.
165162 fn dropck_boring_locals ( & mut self , boring_locals : Vec < Local > ) {
166163 for local in boring_locals {
167- let local_ty = self . cx . body . local_decls [ local] . ty ;
168- let local_span = self . cx . body . local_decls [ local] . source_info . span ;
164+ let local_ty = self . cx . body ( ) . local_decls [ local] . ty ;
165+ let local_span = self . cx . body ( ) . local_decls [ local] . source_info . span ;
169166 let drop_data = self . cx . drop_data . entry ( local_ty) . or_insert_with ( {
170167 let typeck = & self . cx . typeck ;
171168 move || LivenessContext :: compute_drop_data ( typeck, local_ty, local_span)
172169 } ) ;
173170
174171 drop_data. dropck_result . report_overflows (
175172 self . cx . typeck . infcx . tcx ,
176- self . cx . body . local_decls [ local] . source_info . span ,
173+ self . cx . typeck . body . local_decls [ local] . source_info . span ,
177174 local_ty,
178175 ) ;
179176 }
@@ -202,7 +199,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
202199 . var_dropped_at
203200 . iter ( )
204201 . filter_map ( |& ( local, location_index) | {
205- let local_ty = self . cx . body . local_decls [ local] . ty ;
202+ let local_ty = self . cx . body ( ) . local_decls [ local] . ty ;
206203 if relevant_live_locals. contains ( & local) || !local_ty. has_free_regions ( ) {
207204 return None ;
208205 }
@@ -278,9 +275,9 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
278275
279276 let block = self . cx . location_map . to_location ( block_start) . block ;
280277 self . stack . extend (
281- self . cx . body . basic_blocks . predecessors ( ) [ block]
278+ self . cx . body ( ) . basic_blocks . predecessors ( ) [ block]
282279 . iter ( )
283- . map ( |& pred_bb| self . cx . body . terminator_loc ( pred_bb) )
280+ . map ( |& pred_bb| self . cx . body ( ) . terminator_loc ( pred_bb) )
284281 . map ( |pred_loc| self . cx . location_map . point_from_location ( pred_loc) ) ,
285282 ) ;
286283 }
@@ -305,7 +302,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
305302 // Find the drops where `local` is initialized.
306303 for drop_point in self . cx . local_use_map . drops ( local) {
307304 let location = self . cx . location_map . to_location ( drop_point) ;
308- debug_assert_eq ! ( self . cx. body. terminator_loc( location. block) , location, ) ;
305+ debug_assert_eq ! ( self . cx. body( ) . terminator_loc( location. block) , location, ) ;
309306
310307 if self . cx . initialized_at_terminator ( location. block , mpi)
311308 && self . drop_live_at . insert ( drop_point)
@@ -351,7 +348,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
351348 // block. One of them may be either a definition or use
352349 // live point.
353350 let term_location = self . cx . location_map . to_location ( term_point) ;
354- debug_assert_eq ! ( self . cx. body. terminator_loc( term_location. block) , term_location, ) ;
351+ debug_assert_eq ! ( self . cx. body( ) . terminator_loc( term_location. block) , term_location, ) ;
355352 let block = term_location. block ;
356353 let entry_point = self . cx . location_map . entry_point ( term_location. block ) ;
357354 for p in ( entry_point..term_point) . rev ( ) {
@@ -376,7 +373,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
376373 }
377374 }
378375
379- let body = self . cx . body ;
376+ let body = self . cx . typeck . body ;
380377 for & pred_block in body. basic_blocks . predecessors ( ) [ block] . iter ( ) {
381378 debug ! ( "compute_drop_live_points_for_block: pred_block = {:?}" , pred_block, ) ;
382379
@@ -403,7 +400,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
403400 continue ;
404401 }
405402
406- let pred_term_loc = self . cx . body . terminator_loc ( pred_block) ;
403+ let pred_term_loc = self . cx . body ( ) . terminator_loc ( pred_block) ;
407404 let pred_term_point = self . cx . location_map . point_from_location ( pred_term_loc) ;
408405
409406 // If the terminator of this predecessor either *assigns*
@@ -463,6 +460,9 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
463460}
464461
465462impl < ' tcx > LivenessContext < ' _ , ' _ , ' _ , ' tcx > {
463+ fn body ( & self ) -> & Body < ' tcx > {
464+ self . typeck . body
465+ }
466466 /// Returns `true` if the local variable (or some part of it) is initialized at the current
467467 /// cursor position. Callers should call one of the `seek` methods immediately before to point
468468 /// the cursor to the desired location.
@@ -481,7 +481,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
481481 /// DROP of some local variable will have an effect -- note that
482482 /// drops, as they may unwind, are always terminators.
483483 fn initialized_at_terminator ( & mut self , block : BasicBlock , mpi : MovePathIndex ) -> bool {
484- self . flow_inits . seek_before_primary_effect ( self . body . terminator_loc ( block) ) ;
484+ self . flow_inits . seek_before_primary_effect ( self . body ( ) . terminator_loc ( block) ) ;
485485 self . initialized_at_curr_loc ( mpi)
486486 }
487487
@@ -491,7 +491,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
491491 /// **Warning:** Does not account for the result of `Call`
492492 /// instructions.
493493 fn initialized_at_exit ( & mut self , block : BasicBlock , mpi : MovePathIndex ) -> bool {
494- self . flow_inits . seek_after_primary_effect ( self . body . terminator_loc ( block) ) ;
494+ self . flow_inits . seek_after_primary_effect ( self . body ( ) . terminator_loc ( block) ) ;
495495 self . initialized_at_curr_loc ( mpi)
496496 }
497497
@@ -526,7 +526,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
526526 values:: pretty_print_points( self . location_map, live_at. iter( ) ) ,
527527 ) ;
528528
529- let local_span = self . body . local_decls ( ) [ dropped_local] . source_info . span ;
529+ let local_span = self . body ( ) . local_decls ( ) [ dropped_local] . source_info . span ;
530530 let drop_data = self . drop_data . entry ( dropped_ty) . or_insert_with ( {
531531 let typeck = & self . typeck ;
532532 move || Self :: compute_drop_data ( typeck, dropped_ty, local_span)
@@ -544,7 +544,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
544544
545545 drop_data. dropck_result . report_overflows (
546546 self . typeck . infcx . tcx ,
547- self . body . source_info ( * drop_locations. first ( ) . unwrap ( ) ) . span ,
547+ self . typeck . body . source_info ( * drop_locations. first ( ) . unwrap ( ) ) . span ,
548548 dropped_ty,
549549 ) ;
550550
0 commit comments