@@ -211,7 +211,7 @@ fn replace_flattened_locals<'tcx>(
211
211
local_decls : & body. local_decls ,
212
212
replacements,
213
213
all_dead_locals,
214
- fragments,
214
+ fragments : & fragments ,
215
215
patch : MirPatch :: new ( body) ,
216
216
} ;
217
217
for ( bb, data) in body. basic_blocks . as_mut_preserves_cfg ( ) . iter_enumerated_mut ( ) {
@@ -239,7 +239,7 @@ struct ReplacementVisitor<'tcx, 'll> {
239
239
all_dead_locals : BitSet < Local > ,
240
240
/// Pre-computed list of all "new" locals for each "old" local. This is used to expand storage
241
241
/// and deinit statement and debuginfo.
242
- fragments : IndexVec < Local , Option < Vec < ( & ' tcx [ PlaceElem < ' tcx > ] , Local ) > > > ,
242
+ fragments : & ' ll IndexVec < Local , Option < Vec < ( & ' tcx [ PlaceElem < ' tcx > ] , Local ) > > > ,
243
243
patch : MirPatch < ' tcx > ,
244
244
}
245
245
@@ -270,6 +270,14 @@ impl<'tcx, 'll> ReplacementVisitor<'tcx, 'll> {
270
270
None
271
271
}
272
272
}
273
+
274
+ fn place_fragments (
275
+ & self ,
276
+ place : Place < ' tcx > ,
277
+ ) -> Option < & ' ll Vec < ( & ' tcx [ PlaceElem < ' tcx > ] , Local ) > > {
278
+ let local = place. as_local ( ) ?;
279
+ self . fragments [ local] . as_ref ( )
280
+ }
273
281
}
274
282
275
283
impl < ' tcx , ' ll > MutVisitor < ' tcx > for ReplacementVisitor < ' tcx , ' ll > {
@@ -297,25 +305,19 @@ impl<'tcx, 'll> MutVisitor<'tcx> for ReplacementVisitor<'tcx, 'll> {
297
305
}
298
306
return ;
299
307
}
300
- StatementKind :: Deinit ( box ref place) => {
301
- if let Some ( local) = place. as_local ( )
302
- && let Some ( final_locals) = & self . fragments [ local]
303
- {
308
+ StatementKind :: Deinit ( box place) => {
309
+ if let Some ( final_locals) = self . place_fragments ( place) {
304
310
for & ( _, fl) in final_locals {
305
- self . patch . add_statement (
306
- location,
307
- StatementKind :: Deinit ( Box :: new ( fl. into ( ) ) ) ,
308
- ) ;
311
+ self . patch
312
+ . add_statement ( location, StatementKind :: Deinit ( Box :: new ( fl. into ( ) ) ) ) ;
309
313
}
310
314
statement. make_nop ( ) ;
311
315
return ;
312
316
}
313
317
}
314
318
315
- StatementKind :: Assign ( box ( ref place, Rvalue :: Aggregate ( _, ref operands) ) ) => {
316
- if let Some ( local) = place. as_local ( )
317
- && let Some ( final_locals) = & self . fragments [ local]
318
- {
319
+ StatementKind :: Assign ( box ( place, Rvalue :: Aggregate ( _, ref operands) ) ) => {
320
+ if let Some ( final_locals) = self . place_fragments ( place) {
319
321
for & ( projection, fl) in final_locals {
320
322
let & [ PlaceElem :: Field ( index, _) ] = projection else { bug ! ( ) } ;
321
323
let index = index. as_usize ( ) ;
@@ -330,31 +332,28 @@ impl<'tcx, 'll> MutVisitor<'tcx> for ReplacementVisitor<'tcx, 'll> {
330
332
}
331
333
}
332
334
333
- StatementKind :: Assign ( box ( ref place, Rvalue :: Use ( Operand :: Constant ( _) ) ) ) => {
334
- if let Some ( local) = place. as_local ( )
335
- && let Some ( final_locals) = & self . fragments [ local]
336
- {
335
+ StatementKind :: Assign ( box ( place, Rvalue :: Use ( Operand :: Constant ( _) ) ) ) => {
336
+ if let Some ( final_locals) = self . place_fragments ( place) {
337
337
for & ( projection, fl) in final_locals {
338
- let rvalue = Rvalue :: Use ( Operand :: Move ( place. project_deeper ( projection, self . tcx ) ) ) ;
338
+ let rvalue =
339
+ Rvalue :: Use ( Operand :: Move ( place. project_deeper ( projection, self . tcx ) ) ) ;
339
340
self . patch . add_statement (
340
341
location,
341
342
StatementKind :: Assign ( Box :: new ( ( fl. into ( ) , rvalue) ) ) ,
342
343
) ;
343
344
}
344
- self . all_dead_locals . remove ( local) ;
345
+ self . all_dead_locals . remove ( place . local ) ;
345
346
return ;
346
347
}
347
348
}
348
349
349
- StatementKind :: Assign ( box ( ref lhs, Rvalue :: Use ( ref op) ) ) => {
350
+ StatementKind :: Assign ( box ( lhs, Rvalue :: Use ( ref op) ) ) => {
350
351
let ( rplace, copy) = match op {
351
352
Operand :: Copy ( rplace) => ( rplace, true ) ,
352
353
Operand :: Move ( rplace) => ( rplace, false ) ,
353
354
Operand :: Constant ( _) => bug ! ( ) ,
354
355
} ;
355
- if let Some ( local) = lhs. as_local ( )
356
- && let Some ( final_locals) = & self . fragments [ local]
357
- {
356
+ if let Some ( final_locals) = self . place_fragments ( lhs) {
358
357
for & ( projection, fl) in final_locals {
359
358
let rplace = rplace. project_deeper ( projection, self . tcx ) ;
360
359
let rvalue = if copy {
0 commit comments