Skip to content

Commit 37c2861

Browse files
committed
corotuine_clone: add comments
1 parent 54dcff1 commit 37c2861

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,11 @@ pub enum TerminatorKind<'tcx> {
821821
/// continues at the `resume` basic block, with the second argument written to the `resume_arg`
822822
/// place. If the coroutine is dropped before then, the `drop` basic block is invoked.
823823
///
824+
/// Note that coroutines can be (unstably) cloned under certain conditions, which means that
825+
/// this terminator can **return multiple times**! MIR optimizations that reorder code into
826+
/// different basic blocks needs to be aware of that.
827+
/// See <https://github.com/rust-lang/rust/issues/95360>.
828+
///
824829
/// Not permitted in bodies that are not coroutine bodies, or after coroutine lowering.
825830
///
826831
/// **Needs clarification**: What about the evaluation order of the `resume_arg` and `value`?

tests/ui/coroutine/clone-impl-static.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@compile-flags: --diagnostic-width=300
22
// gate-test-coroutine_clone
33
// Verifies that static coroutines cannot be cloned/copied.
4+
// This is important: the cloned coroutine would reference state of the original
5+
// coroutine, leading to semantic nonsense.
46

57
#![feature(coroutines, coroutine_clone, stmt_expr_attributes)]
68

0 commit comments

Comments
 (0)