@@ -277,7 +277,7 @@ where
277277 ( sig. output ( ) , drop_fn_def_id, trait_args)
278278 } ;
279279
280- let fut = Place :: from ( self . new_temp ( fut_ty) ) ;
280+ let fut = self . new_temp ( fut_ty) ;
281281
282282 // #1:pin_obj_bb >>> obj_ref = &mut obj
283283 let obj_ref_ty = Ty :: new_mut_ref ( tcx, tcx. lifetimes . re_erased , drop_ty) ;
@@ -312,20 +312,34 @@ where
312312 // causing StorageLive(fut) to fire again without a preceding StorageDead.
313313 let succ_with_dead = self . new_block_with_statements (
314314 unwind,
315- vec ! [ Statement :: new ( self . source_info , StatementKind :: StorageDead ( fut. local ) ) ] ,
315+ vec ! [ self . storage_dead ( fut) ] ,
316316 TerminatorKind :: Goto { target : succ } ,
317317 ) ;
318+ let dropline_with_dead = dropline. map ( |target| {
319+ self . new_block_with_statements (
320+ unwind,
321+ vec ! [ self . storage_dead( fut) ] ,
322+ TerminatorKind :: Goto { target } ,
323+ )
324+ } ) ;
325+ let unwind_with_dead = unwind. map ( |target| {
326+ self . new_block_with_statements (
327+ Unwind :: InCleanup ,
328+ vec ! [ self . storage_dead( fut) ] ,
329+ TerminatorKind :: Goto { target } ,
330+ )
331+ } ) ;
318332
319333 // #3:drop_term_bb
320334 let drop_term_bb = self . new_block (
321335 unwind,
322336 TerminatorKind :: Drop {
323337 place,
324338 target : succ_with_dead,
325- unwind : unwind . into_action ( ) ,
339+ unwind : unwind_with_dead . into_action ( ) ,
326340 replace : false ,
327- drop : dropline ,
328- async_fut : Some ( fut. local ) ,
341+ drop : dropline_with_dead ,
342+ async_fut : Some ( fut) ,
329343 } ,
330344 ) ;
331345
@@ -350,36 +364,21 @@ where
350364
351365 obj_ref_place
352366 } ;
353- call_statements
354- . push ( Statement :: new ( self . source_info , StatementKind :: StorageLive ( fut. local ) ) ) ;
367+ call_statements. push ( self . storage_live ( fut) ) ;
355368
356369 let call_drop_bb = self . new_block_with_statements (
357370 unwind,
358371 call_statements,
359372 TerminatorKind :: Call {
360373 func : Operand :: function_handle ( tcx, drop_fn_def_id, trait_args, span) ,
361374 args : [ Spanned { node : Operand :: Move ( drop_arg) , span : DUMMY_SP } ] . into ( ) ,
362- destination : fut,
375+ destination : fut. into ( ) ,
363376 target : Some ( drop_term_bb) ,
364- unwind : unwind . into_action ( ) ,
377+ unwind : unwind_with_dead . into_action ( ) ,
365378 call_source : CallSource :: Misc ,
366379 fn_span : self . source_info . span ,
367380 } ,
368381 ) ;
369- // StorageDead(fut) in unwind block (at the begin)
370- if let Unwind :: To ( block) = unwind {
371- self . elaborator . patch ( ) . add_statement (
372- Location { block, statement_index : 0 } ,
373- StatementKind :: StorageDead ( fut. local ) ,
374- ) ;
375- }
376- // StorageDead(fut) in dropline block (at the begin)
377- if let Some ( block) = dropline {
378- self . elaborator . patch ( ) . add_statement (
379- Location { block, statement_index : 0 } ,
380- StatementKind :: StorageDead ( fut. local ) ,
381- ) ;
382- }
383382
384383 // #1:pin_obj_bb >>> call Pin<ObjTy>::new_unchecked(&mut obj)
385384 self . new_block_with_statements (
@@ -1399,4 +1398,12 @@ where
13991398 fn assign ( & self , lhs : Place < ' tcx > , rhs : Rvalue < ' tcx > ) -> Statement < ' tcx > {
14001399 Statement :: new ( self . source_info , StatementKind :: Assign ( Box :: new ( ( lhs, rhs) ) ) )
14011400 }
1401+
1402+ fn storage_live ( & self , local : Local ) -> Statement < ' tcx > {
1403+ Statement :: new ( self . source_info , StatementKind :: StorageLive ( local) )
1404+ }
1405+
1406+ fn storage_dead ( & self , local : Local ) -> Statement < ' tcx > {
1407+ Statement :: new ( self . source_info , StatementKind :: StorageDead ( local) )
1408+ }
14021409}
0 commit comments