@@ -327,12 +327,30 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
327
327
let data = self . mir . basic_block_data ( bb) ;
328
328
let terminator = data. terminator ( ) ;
329
329
330
- let unwind = Some ( unwind. unwrap_or_else ( || {
331
- // we can't use the resume block directly, because we
332
- // may want to add a drop flag write.
333
- self . jump_to_resume_block ( terminator. scope ,
334
- terminator. span )
335
- } ) ) ;
330
+ let assign = Statement {
331
+ kind : StatementKind :: Assign ( location. clone ( ) , Rvalue :: Use ( value. clone ( ) ) ) ,
332
+ span : terminator. span ,
333
+ scope : terminator. scope
334
+ } ;
335
+
336
+ let unwind = unwind. unwrap_or ( self . patch . resume_block ( ) ) ;
337
+ let unwind = self . patch . new_block ( BasicBlockData {
338
+ statements : vec ! [ assign. clone( ) ] ,
339
+ terminator : Some ( Terminator {
340
+ kind : TerminatorKind :: Goto { target : unwind } ,
341
+ ..* terminator
342
+ } ) ,
343
+ is_cleanup : true
344
+ } ) ;
345
+
346
+ let target = self . patch . new_block ( BasicBlockData {
347
+ statements : vec ! [ assign] ,
348
+ terminator : Some ( Terminator {
349
+ kind : TerminatorKind :: Goto { target : target } ,
350
+ ..* terminator
351
+ } ) ,
352
+ is_cleanup : data. is_cleanup ,
353
+ } ) ;
336
354
337
355
if !self . lvalue_is_tracked ( location) {
338
356
// drop and replace behind a pointer/array/whatever. The location
@@ -341,7 +359,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
341
359
self . patch . patch_terminator ( bb, TerminatorKind :: Drop {
342
360
location : location. clone ( ) ,
343
361
target : target,
344
- unwind : unwind
362
+ unwind : Some ( unwind)
345
363
} ) ;
346
364
} else {
347
365
debug ! ( "elaborate_drop_and_replace({:?}) - tracked" , terminator) ;
@@ -356,24 +374,15 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
356
374
lvalue : location,
357
375
path : path,
358
376
succ : target,
359
- unwind : unwind
377
+ unwind : Some ( unwind)
360
378
} , bb) ;
361
379
on_all_children_bits ( self . tcx , self . mir , self . move_data ( ) , path, |child| {
362
380
self . set_drop_flag ( Location { block : target, index : 0 } ,
363
381
child, DropFlagState :: Present ) ;
364
- if let Some ( unwind) = unwind {
365
- self . set_drop_flag ( Location { block : unwind, index : 0 } ,
366
- child, DropFlagState :: Present ) ;
367
- }
382
+ self . set_drop_flag ( Location { block : unwind, index : 0 } ,
383
+ child, DropFlagState :: Present ) ;
368
384
} ) ;
369
385
}
370
-
371
- self . patch . add_assign ( Location { block : target, index : 0 } ,
372
- location. clone ( ) , Rvalue :: Use ( value. clone ( ) ) ) ;
373
- if let Some ( unwind) = unwind {
374
- self . patch . add_assign ( Location { block : unwind, index : 0 } ,
375
- location. clone ( ) , Rvalue :: Use ( value. clone ( ) ) ) ;
376
- }
377
386
}
378
387
379
388
/// This elaborates a single drop instruction, located at `bb`, and
@@ -828,19 +837,6 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
828
837
} )
829
838
}
830
839
831
- fn jump_to_resume_block < ' a > ( & mut self , scope : ScopeId , span : Span ) -> BasicBlock {
832
- let resume_block = self . patch . resume_block ( ) ;
833
- self . patch . new_block ( BasicBlockData {
834
- statements : vec ! [ ] ,
835
- terminator : Some ( Terminator {
836
- scope : scope, span : span, kind : TerminatorKind :: Goto {
837
- target : resume_block
838
- }
839
- } ) ,
840
- is_cleanup : true
841
- } )
842
- }
843
-
844
840
fn box_free_block < ' a > (
845
841
& mut self ,
846
842
c : & DropCtxt < ' a , ' tcx > ,
0 commit comments