@@ -89,6 +89,7 @@ pub(crate) trait DropElaborator<'a, 'tcx>: fmt::Debug {
89
89
90
90
// Accessors
91
91
92
+ fn patch_ref ( & self ) -> & MirPatch < ' tcx > ;
92
93
fn patch ( & mut self ) -> & mut MirPatch < ' tcx > ;
93
94
fn body ( & self ) -> & ' a Body < ' tcx > ;
94
95
fn tcx ( & self ) -> TyCtxt < ' tcx > ;
@@ -180,7 +181,14 @@ where
180
181
{
181
182
#[ instrument( level = "trace" , skip( self ) , ret) ]
182
183
fn place_ty ( & self , place : Place < ' tcx > ) -> Ty < ' tcx > {
183
- place. ty ( self . elaborator . body ( ) , self . tcx ( ) ) . ty
184
+ if place. local < self . elaborator . body ( ) . local_decls . next_index ( ) {
185
+ place. ty ( self . elaborator . body ( ) , self . tcx ( ) ) . ty
186
+ } else {
187
+ // We don't have a slice with all the locals, since some are in the patch.
188
+ tcx:: PlaceTy :: from_ty ( self . elaborator . patch_ref ( ) . local_ty ( place. local ) )
189
+ . multi_projection_ty ( self . elaborator . tcx ( ) , place. projection )
190
+ . ty
191
+ }
184
192
}
185
193
186
194
fn tcx ( & self ) -> TyCtxt < ' tcx > {
@@ -410,12 +418,26 @@ where
410
418
411
419
let unique_place = self . tcx ( ) . mk_place_field ( self . place , FieldIdx :: ZERO , unique_ty) ;
412
420
let nonnull_place = self . tcx ( ) . mk_place_field ( unique_place, FieldIdx :: ZERO , nonnull_ty) ;
413
- let ptr_place = self . tcx ( ) . mk_place_field ( nonnull_place, FieldIdx :: ZERO , ptr_ty) ;
414
- let interior = self . tcx ( ) . mk_place_deref ( ptr_place) ;
415
421
422
+ let ptr_local = self . new_temp ( ptr_ty) ;
423
+
424
+ let interior = self . tcx ( ) . mk_place_deref ( Place :: from ( ptr_local) ) ;
416
425
let interior_path = self . elaborator . deref_subpath ( self . path ) ;
417
426
418
- self . drop_subpath ( interior, interior_path, succ, unwind)
427
+ let do_drop_bb = self . drop_subpath ( interior, interior_path, succ, unwind) ;
428
+
429
+ let setup_bbd = BasicBlockData {
430
+ statements : vec ! [ self . assign(
431
+ Place :: from( ptr_local) ,
432
+ Rvalue :: Cast ( CastKind :: Transmute , Operand :: Copy ( nonnull_place) , ptr_ty) ,
433
+ ) ] ,
434
+ terminator : Some ( Terminator {
435
+ kind : TerminatorKind :: Goto { target : do_drop_bb } ,
436
+ source_info : self . source_info ,
437
+ } ) ,
438
+ is_cleanup : unwind. is_cleanup ( ) ,
439
+ } ;
440
+ self . elaborator . patch ( ) . new_block ( setup_bbd)
419
441
}
420
442
421
443
#[ instrument( level = "debug" , ret) ]
0 commit comments