@@ -96,8 +96,6 @@ pub(crate) trait DropElaborator<'a, 'tcx>: fmt::Debug {
9696 fn typing_env ( & self ) -> ty:: TypingEnv < ' tcx > ;
9797 fn allow_async_drops ( & self ) -> bool ;
9898
99- fn terminator_loc ( & self , bb : BasicBlock ) -> Location ;
100-
10199 // Drop logic
102100
103101 /// Returns how `path` should be dropped, given `mode`.
@@ -200,19 +198,18 @@ where
200198 self . elaborator . tcx ( )
201199 }
202200
203- // Generates three blocks:
204- // * #1:pin_obj_bb: call Pin<ObjTy>::new_unchecked(&mut obj)
205- // * #2:call_drop_bb: fut = call obj.<AsyncDrop::drop>() OR call async_drop_in_place<T>(obj)
206- // * #3:drop_term_bb: drop (obj, fut, ...)
207- // We keep async drop unexpanded to poll-loop here, to expand it later, at StateTransform -
208- // into states expand.
209- // call_destructor_only - to call only AsyncDrop::drop, not full async_drop_in_place glue
201+ /// Generates three blocks:
202+ /// * #1:pin_obj_bb: call Pin<ObjTy>::new_unchecked(&mut obj)
203+ /// * #2:call_drop_bb: fut = call obj.<AsyncDrop::drop>() OR call async_drop_in_place<T>(obj)
204+ /// * #3:drop_term_bb: drop (obj, fut, ...)
205+ /// We keep async drop unexpanded to poll-loop here, to expand it later, at StateTransform -
206+ /// into states expand.
207+ /// call_destructor_only - to call only AsyncDrop::drop, not full async_drop_in_place glue
210208 #[ instrument( level = "debug" , skip( self ) , ret) ]
211209 fn build_async_drop (
212210 & mut self ,
213211 place : Place < ' tcx > ,
214212 drop_ty : Ty < ' tcx > ,
215- bb : Option < BasicBlock > ,
216213 succ : BasicBlock ,
217214 unwind : Unwind ,
218215 dropline : Option < BasicBlock > ,
@@ -221,11 +218,6 @@ where
221218 let tcx = self . tcx ( ) ;
222219 let span = self . source_info . span ;
223220
224- let pin_obj_bb = bb. unwrap_or_else ( || {
225- // Temporary terminator, will be replaced by patch
226- self . new_block ( unwind, TerminatorKind :: Return )
227- } ) ;
228-
229221 let ( fut_ty, drop_fn_def_id, trait_args) = if call_destructor_only {
230222 // Resolving obj.<AsyncDrop::drop>()
231223 let trait_ref =
@@ -260,8 +252,8 @@ where
260252 self . elaborator . body ( ) . span ,
261253 "AsyncDrop type without correct `async fn drop(...)`." ,
262254 ) ;
263- self . elaborator . patch ( ) . patch_terminator (
264- pin_obj_bb ,
255+ return self . new_block (
256+ unwind ,
265257 TerminatorKind :: Drop {
266258 place,
267259 target : succ,
@@ -271,7 +263,6 @@ where
271263 async_fut : None ,
272264 } ,
273265 ) ;
274- return pin_obj_bb;
275266 } ;
276267 let drop_fn = Ty :: new_fn_def ( tcx, drop_fn_def_id, trait_args) ;
277268 let sig = drop_fn. fn_sig ( tcx) ;
@@ -291,10 +282,7 @@ where
291282 // #1:pin_obj_bb >>> obj_ref = &mut obj
292283 let obj_ref_ty = Ty :: new_mut_ref ( tcx, tcx. lifetimes . re_erased , drop_ty) ;
293284 let obj_ref_place = Place :: from ( self . new_temp ( obj_ref_ty) ) ;
294-
295- let term_loc = self . elaborator . terminator_loc ( pin_obj_bb) ;
296- self . elaborator . patch ( ) . add_assign (
297- term_loc,
285+ let assign_obj_ref_place = self . assign (
298286 obj_ref_place,
299287 Rvalue :: Ref (
300288 tcx. lifetimes . re_erased ,
@@ -394,8 +382,9 @@ where
394382 }
395383
396384 // #1:pin_obj_bb >>> call Pin<ObjTy>::new_unchecked(&mut obj)
397- self . elaborator . patch ( ) . patch_terminator (
398- pin_obj_bb,
385+ self . new_block_with_statements (
386+ unwind,
387+ vec ! [ assign_obj_ref_place] ,
399388 TerminatorKind :: Call {
400389 func : pin_obj_new_unchecked_fn,
401390 args : [ dummy_spanned ( Operand :: Move ( obj_ref_place) ) ] . into ( ) ,
@@ -405,24 +394,25 @@ where
405394 call_source : CallSource :: Misc ,
406395 fn_span : span,
407396 } ,
408- ) ;
409- pin_obj_bb
397+ )
410398 }
411399
412400 fn build_drop ( & mut self , bb : BasicBlock ) {
413401 let drop_ty = self . place_ty ( self . place ) ;
414402 if !self . elaborator . patch_ref ( ) . block ( self . elaborator . body ( ) , bb) . is_cleanup
415403 && self . check_if_can_async_drop ( drop_ty, false )
416404 {
417- self . build_async_drop (
405+ let async_drop_bb = self . build_async_drop (
418406 self . place ,
419407 drop_ty,
420- Some ( bb) ,
421408 self . succ ,
422409 self . unwind ,
423410 self . dropline ,
424411 false ,
425412 ) ;
413+ self . elaborator
414+ . patch ( )
415+ . patch_terminator ( bb, TerminatorKind :: Goto { target : async_drop_bb } ) ;
426416 } else {
427417 self . elaborator . patch ( ) . patch_terminator (
428418 bb,
@@ -1005,7 +995,7 @@ where
1005995 ) -> BasicBlock {
1006996 let ty = self . place_ty ( self . place ) ;
1007997 if !unwind. is_cleanup ( ) && self . check_if_can_async_drop ( ty, true ) {
1008- self . build_async_drop ( self . place , ty, None , succ, unwind, dropline, true )
998+ self . build_async_drop ( self . place , ty, succ, unwind, dropline, true )
1009999 } else {
10101000 self . destructor_call_block_sync ( succ, unwind)
10111001 }
@@ -1067,15 +1057,11 @@ where
10671057
10681058 let place = tcx. mk_place_deref ( ptr) ;
10691059 if !unwind. is_cleanup ( ) && self . check_if_can_async_drop ( ety, false ) {
1070- self . build_async_drop (
1071- place,
1072- ety,
1073- Some ( drop_block) ,
1074- loop_block,
1075- unwind,
1076- dropline,
1077- false ,
1078- ) ;
1060+ let async_drop_bb =
1061+ self . build_async_drop ( place, ety, loop_block, unwind, dropline, false ) ;
1062+ self . elaborator
1063+ . patch ( )
1064+ . patch_terminator ( drop_block, TerminatorKind :: Goto { target : async_drop_bb } ) ;
10791065 } else {
10801066 self . elaborator . patch ( ) . patch_terminator (
10811067 drop_block,
@@ -1331,15 +1317,7 @@ where
13311317 fn drop_block ( & mut self , target : BasicBlock , unwind : Unwind ) -> BasicBlock {
13321318 let drop_ty = self . place_ty ( self . place ) ;
13331319 if !unwind. is_cleanup ( ) && self . check_if_can_async_drop ( drop_ty, false ) {
1334- self . build_async_drop (
1335- self . place ,
1336- drop_ty,
1337- None ,
1338- self . succ ,
1339- unwind,
1340- self . dropline ,
1341- false ,
1342- )
1320+ self . build_async_drop ( self . place , drop_ty, self . succ , unwind, self . dropline , false )
13431321 } else {
13441322 self . new_block (
13451323 unwind,
0 commit comments