Skip to content

Commit 8f9fede

Browse files
committed
coroutine_clone: add comments
1 parent 54dcff1 commit 8f9fede

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

compiler/rustc_middle/src/mir/syntax.rs

+5
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

+2
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

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
error[E0277]: the trait bound `{static coroutine@$DIR/clone-impl-static.rs:9:5: 9:19}: Copy` is not satisfied
2-
--> $DIR/clone-impl-static.rs:12:16
1+
error[E0277]: the trait bound `{static coroutine@$DIR/clone-impl-static.rs:11:5: 11:19}: Copy` is not satisfied
2+
--> $DIR/clone-impl-static.rs:14:16
33
|
44
LL | check_copy(&gen);
5-
| ---------- ^^^^ the trait `Copy` is not implemented for `{static coroutine@$DIR/clone-impl-static.rs:9:5: 9:19}`
5+
| ---------- ^^^^ the trait `Copy` is not implemented for `{static coroutine@$DIR/clone-impl-static.rs:11:5: 11:19}`
66
| |
77
| required by a bound introduced by this call
88
|
99
note: required by a bound in `check_copy`
10-
--> $DIR/clone-impl-static.rs:18:18
10+
--> $DIR/clone-impl-static.rs:20:18
1111
|
1212
LL | fn check_copy<T: Copy>(_x: &T) {}
1313
| ^^^^ required by this bound in `check_copy`
1414

15-
error[E0277]: the trait bound `{static coroutine@$DIR/clone-impl-static.rs:9:5: 9:19}: Clone` is not satisfied
16-
--> $DIR/clone-impl-static.rs:14:17
15+
error[E0277]: the trait bound `{static coroutine@$DIR/clone-impl-static.rs:11:5: 11:19}: Clone` is not satisfied
16+
--> $DIR/clone-impl-static.rs:16:17
1717
|
1818
LL | check_clone(&gen);
19-
| ----------- ^^^^ the trait `Clone` is not implemented for `{static coroutine@$DIR/clone-impl-static.rs:9:5: 9:19}`
19+
| ----------- ^^^^ the trait `Clone` is not implemented for `{static coroutine@$DIR/clone-impl-static.rs:11:5: 11:19}`
2020
| |
2121
| required by a bound introduced by this call
2222
|
2323
note: required by a bound in `check_clone`
24-
--> $DIR/clone-impl-static.rs:19:19
24+
--> $DIR/clone-impl-static.rs:21:19
2525
|
2626
LL | fn check_clone<T: Clone>(_x: &T) {}
2727
| ^^^^^ required by this bound in `check_clone`

0 commit comments

Comments
 (0)