@@ -89,6 +89,7 @@ pub(crate) trait DropElaborator<'a, 'tcx>: fmt::Debug {
8989
9090 // Accessors
9191
92+ fn patch_ref ( & self ) -> & MirPatch < ' tcx > ;
9293 fn patch ( & mut self ) -> & mut MirPatch < ' tcx > ;
9394 fn body ( & self ) -> & ' a Body < ' tcx > ;
9495 fn tcx ( & self ) -> TyCtxt < ' tcx > ;
@@ -180,7 +181,14 @@ where
180181{
181182 #[ instrument( level = "trace" , skip( self ) , ret) ]
182183 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+ }
184192 }
185193
186194 fn tcx ( & self ) -> TyCtxt < ' tcx > {
@@ -410,12 +418,26 @@ where
410418
411419 let unique_place = self . tcx ( ) . mk_place_field ( self . place , FieldIdx :: ZERO , unique_ty) ;
412420 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) ;
415421
422+ let ptr_local = self . new_temp ( ptr_ty) ;
423+
424+ let interior = self . tcx ( ) . mk_place_deref ( Place :: from ( ptr_local) ) ;
416425 let interior_path = self . elaborator . deref_subpath ( self . path ) ;
417426
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)
419441 }
420442
421443 #[ instrument( level = "debug" , ret) ]
0 commit comments