@@ -656,7 +656,35 @@ pub enum TerminatorKind<'tcx> {
656
656
/// The `replace` flag indicates whether this terminator was created as part of an assignment.
657
657
/// This should only be used for diagnostic purposes, and does not have any operational
658
658
/// meaning.
659
- Drop { place : Place < ' tcx > , target : BasicBlock , unwind : UnwindAction , replace : bool } ,
659
+ ///
660
+ /// Async drop processing:
661
+ /// In compiler/rustc_mir_build/src/build/scope.rs we detect possible async drop:
662
+ /// drop of object implementing `AsyncDrop` trait or
663
+ /// drop of coroutine (or `Alias(Opaque(...))` of coroutine).
664
+ /// Async drop later, in StateTransform pass, may be expanded into additional yield-point
665
+ /// for poll-loop of async drop future.
666
+ /// So we need prepared 'drop' target block in the similar way as for `Yield` terminator
667
+ /// (see `drops.build_mir::<CoroutineDrop>` in scopes.rs).
668
+ /// In compiler/rustc_mir_transform/src/elaborate_drops.rs for object implementing `AsyncDrop` trait
669
+ /// we need to prepare async drop feature - resolve `AsyncDrop::drop` and codegen call.
670
+ /// `async_fut` is set to the corresponding local.
671
+ /// For coroutine drop we don't need this logic because coroutine drop works with the same
672
+ /// layout object as coroutine itself. So `async_fut` will be `None` for coroutine drop.
673
+ /// Both `drop` and `async_fut` fields are only used in compiler/rustc_mir_transform/src/coroutine.rs,
674
+ /// StateTransform pass. In `expand_async_drops` async drops are expanded
675
+ /// into one or two yield points with poll ready/pending switch.
676
+ /// When a coroutine has any internal async drop, the coroutine drop function will be async
677
+ /// (generated by `create_coroutine_drop_shim_async`, not `create_coroutine_drop_shim`).
678
+ Drop {
679
+ place : Place < ' tcx > ,
680
+ target : BasicBlock ,
681
+ unwind : UnwindAction ,
682
+ replace : bool ,
683
+ /// Cleanup to be done if the coroutine is dropped at this suspend point (for async drop).
684
+ drop : Option < BasicBlock > ,
685
+ /// Prepared async future local (for async drop)
686
+ async_fut : Option < Local > ,
687
+ } ,
660
688
661
689
/// Roughly speaking, evaluates the `func` operand and the arguments, and starts execution of
662
690
/// the referred to function. The operand types must match the argument types of the function.
@@ -888,6 +916,7 @@ pub enum AssertKind<O> {
888
916
RemainderByZero ( O ) ,
889
917
ResumedAfterReturn ( CoroutineKind ) ,
890
918
ResumedAfterPanic ( CoroutineKind ) ,
919
+ ResumedAfterDrop ( CoroutineKind ) ,
891
920
MisalignedPointerDereference { required : O , found : O } ,
892
921
}
893
922
0 commit comments