@@ -211,7 +211,7 @@ fn replace_flattened_locals<'tcx>(
211211 local_decls : & body. local_decls ,
212212 replacements,
213213 all_dead_locals,
214- fragments,
214+ fragments : & fragments ,
215215 patch : MirPatch :: new ( body) ,
216216 } ;
217217 for ( bb, data) in body. basic_blocks . as_mut_preserves_cfg ( ) . iter_enumerated_mut ( ) {
@@ -239,7 +239,7 @@ struct ReplacementVisitor<'tcx, 'll> {
239239 all_dead_locals : BitSet < Local > ,
240240 /// Pre-computed list of all "new" locals for each "old" local. This is used to expand storage
241241 /// 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 ) > > > ,
243243 patch : MirPatch < ' tcx > ,
244244}
245245
@@ -270,6 +270,14 @@ impl<'tcx, 'll> ReplacementVisitor<'tcx, 'll> {
270270 None
271271 }
272272 }
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+ }
273281}
274282
275283impl < ' tcx , ' ll > MutVisitor < ' tcx > for ReplacementVisitor < ' tcx , ' ll > {
@@ -297,25 +305,19 @@ impl<'tcx, 'll> MutVisitor<'tcx> for ReplacementVisitor<'tcx, 'll> {
297305 }
298306 return ;
299307 }
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) {
304310 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 ( ) ) ) ) ;
309313 }
310314 statement. make_nop ( ) ;
311315 return ;
312316 }
313317 }
314318
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) {
319321 for & ( projection, fl) in final_locals {
320322 let & [ PlaceElem :: Field ( index, _) ] = projection else { bug ! ( ) } ;
321323 let index = index. as_usize ( ) ;
@@ -330,31 +332,28 @@ impl<'tcx, 'll> MutVisitor<'tcx> for ReplacementVisitor<'tcx, 'll> {
330332 }
331333 }
332334
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) {
337337 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 ) ) ) ;
339340 self . patch . add_statement (
340341 location,
341342 StatementKind :: Assign ( Box :: new ( ( fl. into ( ) , rvalue) ) ) ,
342343 ) ;
343344 }
344- self . all_dead_locals . remove ( local) ;
345+ self . all_dead_locals . remove ( place . local ) ;
345346 return ;
346347 }
347348 }
348349
349- StatementKind :: Assign ( box ( ref lhs, Rvalue :: Use ( ref op) ) ) => {
350+ StatementKind :: Assign ( box ( lhs, Rvalue :: Use ( ref op) ) ) => {
350351 let ( rplace, copy) = match op {
351352 Operand :: Copy ( rplace) => ( rplace, true ) ,
352353 Operand :: Move ( rplace) => ( rplace, false ) ,
353354 Operand :: Constant ( _) => bug ! ( ) ,
354355 } ;
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) {
358357 for & ( projection, fl) in final_locals {
359358 let rplace = rplace. project_deeper ( projection, self . tcx ) ;
360359 let rvalue = if copy {
0 commit comments