@@ -16,6 +16,7 @@ use super::{
16
16
17
17
struct MoveDataBuilder < ' a , ' tcx , F > {
18
18
body : & ' a Body < ' tcx > ,
19
+ loc : Location ,
19
20
tcx : TyCtxt < ' tcx > ,
20
21
param_env : ty:: ParamEnv < ' tcx > ,
21
22
data : MoveData < ' tcx > ,
@@ -56,6 +57,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
56
57
57
58
MoveDataBuilder {
58
59
body,
60
+ loc : Location :: START ,
59
61
tcx,
60
62
param_env,
61
63
data : MoveData {
@@ -107,7 +109,7 @@ enum MovePathResult {
107
109
Error ,
108
110
}
109
111
110
- impl < ' b , ' a , ' tcx , F : Fn ( Ty < ' tcx > ) -> bool > Gatherer < ' b , ' a , ' tcx , F > {
112
+ impl < ' a , ' tcx , F : Fn ( Ty < ' tcx > ) -> bool > MoveDataBuilder < ' a , ' tcx , F > {
111
113
/// This creates a MovePath for a given place, returning an `MovePathError`
112
114
/// if that place can't be moved from.
113
115
///
@@ -116,7 +118,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
116
118
///
117
119
/// Maybe we should have separate "borrowck" and "moveck" modes.
118
120
fn move_path_for ( & mut self , place : Place < ' tcx > ) -> MovePathResult {
119
- let data = & mut self . builder . data ;
121
+ let data = & mut self . data ;
120
122
121
123
debug ! ( "lookup({:?})" , place) ;
122
124
let Some ( mut base) = data. rev_lookup . find_local ( place. local ) else {
@@ -131,8 +133,8 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
131
133
let mut union_path = None ;
132
134
133
135
for ( place_ref, elem) in data. rev_lookup . un_derefer . iter_projections ( place. as_ref ( ) ) {
134
- let body = self . builder . body ;
135
- let tcx = self . builder . tcx ;
136
+ let body = self . body ;
137
+ let tcx = self . tcx ;
136
138
let place_ty = place_ref. ty ( body, tcx) . ty ;
137
139
if place_ty. references_error ( ) {
138
140
return MovePathResult :: Error ;
@@ -238,7 +240,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
238
240
| ProjectionElem :: Downcast ( _, _) => ( ) ,
239
241
}
240
242
let elem_ty = PlaceTy :: from_ty ( place_ty) . projection_ty ( tcx, elem) . ty ;
241
- if !( self . builder . filter ) ( elem_ty) {
243
+ if !( self . filter ) ( elem_ty) {
242
244
return MovePathResult :: Error ;
243
245
}
244
246
if union_path. is_none ( ) {
@@ -274,7 +276,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
274
276
data : MoveData { rev_lookup, move_paths, path_map, init_path_map, .. } ,
275
277
tcx,
276
278
..
277
- } = self . builder ;
279
+ } = self ;
278
280
* rev_lookup. projections . entry ( ( base, elem. lift ( ) ) ) . or_insert_with ( move || {
279
281
new_move_path ( move_paths, path_map, init_path_map, Some ( base) , mk_place ( * tcx) )
280
282
} )
@@ -285,9 +287,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
285
287
// drop), so this not being a valid move path is OK.
286
288
let _ = self . move_path_for ( place) ;
287
289
}
288
- }
289
290
290
- impl < ' a , ' tcx , F > MoveDataBuilder < ' a , ' tcx , F > {
291
291
fn finalize ( self ) -> MoveData < ' tcx > {
292
292
debug ! ( "{}" , {
293
293
debug!( "moves for {:?}:" , self . body. span) ;
@@ -317,12 +317,12 @@ pub(super) fn gather_moves<'tcx>(
317
317
318
318
for ( bb, block) in body. basic_blocks . iter_enumerated ( ) {
319
319
for ( i, stmt) in block. statements . iter ( ) . enumerate ( ) {
320
- let source = Location { block : bb, statement_index : i } ;
321
- builder. gather_statement ( source , stmt) ;
320
+ builder . loc = Location { block : bb, statement_index : i } ;
321
+ builder. gather_statement ( stmt) ;
322
322
}
323
323
324
- let terminator_loc = Location { block : bb, statement_index : block. statements . len ( ) } ;
325
- builder. gather_terminator ( terminator_loc , block. terminator ( ) ) ;
324
+ builder . loc = Location { block : bb, statement_index : block. statements . len ( ) } ;
325
+ builder. gather_terminator ( block. terminator ( ) ) ;
326
326
}
327
327
328
328
builder. finalize ( )
@@ -345,30 +345,14 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
345
345
}
346
346
}
347
347
348
- fn gather_statement ( & mut self , loc : Location , stmt : & Statement < ' tcx > ) {
349
- debug ! ( "gather_statement({:?}, {:?})" , loc, stmt) ;
350
- ( Gatherer { builder : self , loc } ) . gather_statement ( stmt) ;
351
- }
352
-
353
- fn gather_terminator ( & mut self , loc : Location , term : & Terminator < ' tcx > ) {
354
- debug ! ( "gather_terminator({:?}, {:?})" , loc, term) ;
355
- ( Gatherer { builder : self , loc } ) . gather_terminator ( term) ;
356
- }
357
- }
358
-
359
- struct Gatherer < ' b , ' a , ' tcx , F > {
360
- builder : & ' b mut MoveDataBuilder < ' a , ' tcx , F > ,
361
- loc : Location ,
362
- }
363
-
364
- impl < ' b , ' a , ' tcx , F : Fn ( Ty < ' tcx > ) -> bool > Gatherer < ' b , ' a , ' tcx , F > {
365
348
fn gather_statement ( & mut self , stmt : & Statement < ' tcx > ) {
349
+ debug ! ( "gather_statement({:?}, {:?})" , self . loc, stmt) ;
366
350
match & stmt. kind {
367
351
StatementKind :: Assign ( box ( place, Rvalue :: CopyForDeref ( reffed) ) ) => {
368
352
let local = place. as_local ( ) . unwrap ( ) ;
369
- assert ! ( self . builder . body. local_decls[ local] . is_deref_temp( ) ) ;
353
+ assert ! ( self . body. local_decls[ local] . is_deref_temp( ) ) ;
370
354
371
- let rev_lookup = & mut self . builder . data . rev_lookup ;
355
+ let rev_lookup = & mut self . data . rev_lookup ;
372
356
373
357
rev_lookup. un_derefer . insert ( local, reffed. as_ref ( ) ) ;
374
358
let base_local = rev_lookup. un_derefer . deref_chain ( local) . first ( ) . unwrap ( ) . local ;
@@ -380,7 +364,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
380
364
// Box starts out uninitialized - need to create a separate
381
365
// move-path for the interior so it will be separate from
382
366
// the exterior.
383
- self . create_move_path ( self . builder . tcx . mk_place_deref ( * place) ) ;
367
+ self . create_move_path ( self . tcx . mk_place_deref ( * place) ) ;
384
368
self . gather_init ( place. as_ref ( ) , InitKind :: Shallow ) ;
385
369
} else {
386
370
self . gather_init ( place. as_ref ( ) , InitKind :: Deep ) ;
@@ -393,7 +377,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
393
377
StatementKind :: StorageLive ( _) => { }
394
378
StatementKind :: StorageDead ( local) => {
395
379
// DerefTemp locals (results of CopyForDeref) don't actually move anything.
396
- if !self . builder . body . local_decls [ * local] . is_deref_temp ( ) {
380
+ if !self . body . local_decls [ * local] . is_deref_temp ( ) {
397
381
self . gather_move ( Place :: from ( * local) ) ;
398
382
}
399
383
}
@@ -443,6 +427,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
443
427
}
444
428
445
429
fn gather_terminator ( & mut self , term : & Terminator < ' tcx > ) {
430
+ debug ! ( "gather_terminator({:?}, {:?})" , self . loc, term) ;
446
431
match term. kind {
447
432
TerminatorKind :: Goto { target : _ }
448
433
| TerminatorKind :: FalseEdge { .. }
@@ -551,7 +536,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
551
536
// `ConstIndex` patterns. This is done to ensure that all move paths
552
537
// are disjoint, which is expected by drop elaboration.
553
538
let base_place =
554
- Place { local : place. local , projection : self . builder . tcx . mk_place_elems ( base) } ;
539
+ Place { local : place. local , projection : self . tcx . mk_place_elems ( base) } ;
555
540
let base_path = match self . move_path_for ( base_place) {
556
541
MovePathResult :: Path ( path) => path,
557
542
MovePathResult :: Union ( path) => {
@@ -562,11 +547,9 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
562
547
return ;
563
548
}
564
549
} ;
565
- let base_ty = base_place. ty ( self . builder . body , self . builder . tcx ) . ty ;
550
+ let base_ty = base_place. ty ( self . body , self . tcx ) . ty ;
566
551
let len: u64 = match base_ty. kind ( ) {
567
- ty:: Array ( _, size) => {
568
- size. eval_target_usize ( self . builder . tcx , self . builder . param_env )
569
- }
552
+ ty:: Array ( _, size) => size. eval_target_usize ( self . tcx , self . param_env ) ,
570
553
_ => bug ! ( "from_end: false slice pattern of non-array type" ) ,
571
554
} ;
572
555
for offset in from..to {
@@ -587,13 +570,13 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
587
570
}
588
571
589
572
fn record_move ( & mut self , place : Place < ' tcx > , path : MovePathIndex ) {
590
- let move_out = self . builder . data . moves . push ( MoveOut { path, source : self . loc } ) ;
573
+ let move_out = self . data . moves . push ( MoveOut { path, source : self . loc } ) ;
591
574
debug ! (
592
575
"gather_move({:?}, {:?}): adding move {:?} of {:?}" ,
593
576
self . loc, place, move_out, path
594
577
) ;
595
- self . builder . data . path_map [ path] . push ( move_out) ;
596
- self . builder . data . loc_map [ self . loc ] . push ( move_out) ;
578
+ self . data . path_map [ path] . push ( move_out) ;
579
+ self . data . loc_map [ self . loc ] . push ( move_out) ;
597
580
}
598
581
599
582
fn gather_init ( & mut self , place : PlaceRef < ' tcx > , kind : InitKind ) {
@@ -604,13 +587,13 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
604
587
// Check if we are assigning into a field of a union, if so, lookup the place
605
588
// of the union so it is marked as initialized again.
606
589
if let Some ( ( place_base, ProjectionElem :: Field ( _, _) ) ) = place. last_projection ( ) {
607
- if place_base. ty ( self . builder . body , self . builder . tcx ) . ty . is_union ( ) {
590
+ if place_base. ty ( self . body , self . tcx ) . ty . is_union ( ) {
608
591
place = place_base;
609
592
}
610
593
}
611
594
612
- if let LookupResult :: Exact ( path) = self . builder . data . rev_lookup . find ( place) {
613
- let init = self . builder . data . inits . push ( Init {
595
+ if let LookupResult :: Exact ( path) = self . data . rev_lookup . find ( place) {
596
+ let init = self . data . inits . push ( Init {
614
597
location : InitLocation :: Statement ( self . loc ) ,
615
598
path,
616
599
kind,
@@ -621,8 +604,8 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
621
604
self . loc, place, init, path
622
605
) ;
623
606
624
- self . builder . data . init_path_map [ path] . push ( init) ;
625
- self . builder . data . init_loc_map [ self . loc ] . push ( init) ;
607
+ self . data . init_path_map [ path] . push ( init) ;
608
+ self . data . init_loc_map [ self . loc ] . push ( init) ;
626
609
}
627
610
}
628
611
}
0 commit comments