Skip to content

Commit cece90c

Browse files
committed
Feature gate coroutine yield usage
1 parent 2e5b367 commit cece90c

File tree

7 files changed

+86
-15
lines changed

7 files changed

+86
-15
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,12 +1504,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
15041504

15051505
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
15061506
match self.coroutine_kind {
1507-
Some(hir::CoroutineKind::Coroutine) => {}
15081507
Some(hir::CoroutineKind::Gen(_)) => {}
15091508
Some(hir::CoroutineKind::Async(_)) => {
15101509
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span });
15111510
}
1512-
None => self.coroutine_kind = Some(hir::CoroutineKind::Coroutine),
1511+
Some(hir::CoroutineKind::Coroutine) | None => {
1512+
if !self.tcx.features().coroutines {
1513+
rustc_session::parse::feature_err(
1514+
&self.tcx.sess.parse_sess,
1515+
sym::coroutines,
1516+
span,
1517+
"yield syntax is experimental",
1518+
)
1519+
.emit();
1520+
}
1521+
self.coroutine_kind = Some(hir::CoroutineKind::Coroutine)
1522+
}
15131523
}
15141524

15151525
let expr =
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
error[E0658]: yield syntax is experimental
2+
--> $DIR/gen_block.rs:15:16
3+
|
4+
LL | let _ = || yield true;
5+
| ^^^^^^^^^^
6+
|
7+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
8+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
9+
110
error[E0282]: type annotations needed
211
--> $DIR/gen_block.rs:6:17
312
|
413
LL | let x = gen {};
514
| ^^ cannot infer type
615

7-
error: aborting due to previous error
16+
error: aborting due to 2 previous errors
817

9-
For more information about this error, try `rustc --explain E0282`.
18+
Some errors have detailed explanations: E0282, E0658.
19+
For more information about an error, try `rustc --explain E0282`.

tests/ui/coroutine/gen_block.none.stderr

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,25 @@ LL | gen {};
2525
| ^^^ not found in this scope
2626

2727
error[E0658]: yield syntax is experimental
28-
--> $DIR/gen_block.rs:14:16
28+
--> $DIR/gen_block.rs:15:16
2929
|
3030
LL | let _ = || yield true;
3131
| ^^^^^^^^^^
3232
|
3333
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
3434
= help: add `#![feature(coroutines)]` to the crate attributes to enable
3535

36-
error: aborting due to 5 previous errors
36+
error[E0658]: yield syntax is experimental
37+
--> $DIR/gen_block.rs:15:16
38+
|
39+
LL | let _ = || yield true;
40+
| ^^^^^^^^^^
41+
|
42+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
43+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
44+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
45+
46+
error: aborting due to 6 previous errors
3747

3848
Some errors have detailed explanations: E0422, E0658.
3949
For more information about an error, try `rustc --explain E0422`.

tests/ui/coroutine/gen_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ fn main() {
1212
gen {};
1313
//[none]~^ ERROR: cannot find
1414

15-
// FIXME(gen_blocks): should also error in 2024 edition
1615
let _ = || yield true; //[none]~ ERROR yield syntax is experimental
16+
//~^ ERROR yield syntax is experimental
1717
}
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
error[E0658]: yield syntax is experimental
2+
--> $DIR/feature-gate-coroutines.rs:5:5
3+
|
4+
LL | yield true;
5+
| ^^^^^^^^^^
6+
|
7+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
8+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
9+
10+
error[E0658]: yield syntax is experimental
11+
--> $DIR/feature-gate-coroutines.rs:9:16
12+
|
13+
LL | let _ = || yield true;
14+
| ^^^^^^^^^^
15+
|
16+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
17+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
18+
119
error[E0627]: yield expression outside of coroutine literal
220
--> $DIR/feature-gate-coroutines.rs:5:5
321
|
422
LL | yield true;
523
| ^^^^^^^^^^
624

7-
error: aborting due to previous error
25+
error: aborting due to 3 previous errors
826

9-
For more information about this error, try `rustc --explain E0627`.
27+
Some errors have detailed explanations: E0627, E0658.
28+
For more information about an error, try `rustc --explain E0627`.

tests/ui/feature-gates/feature-gate-coroutines.none.stderr

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | yield true;
88
= help: add `#![feature(coroutines)]` to the crate attributes to enable
99

1010
error[E0658]: yield syntax is experimental
11-
--> $DIR/feature-gate-coroutines.rs:8:16
11+
--> $DIR/feature-gate-coroutines.rs:9:16
1212
|
1313
LL | let _ = || yield true;
1414
| ^^^^^^^^^^
@@ -17,7 +17,7 @@ LL | let _ = || yield true;
1717
= help: add `#![feature(coroutines)]` to the crate attributes to enable
1818

1919
error[E0658]: yield syntax is experimental
20-
--> $DIR/feature-gate-coroutines.rs:14:5
20+
--> $DIR/feature-gate-coroutines.rs:16:5
2121
|
2222
LL | yield;
2323
| ^^^^^
@@ -26,21 +26,41 @@ LL | yield;
2626
= help: add `#![feature(coroutines)]` to the crate attributes to enable
2727

2828
error[E0658]: yield syntax is experimental
29-
--> $DIR/feature-gate-coroutines.rs:15:5
29+
--> $DIR/feature-gate-coroutines.rs:17:5
3030
|
3131
LL | yield 0;
3232
| ^^^^^^^
3333
|
3434
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
3535
= help: add `#![feature(coroutines)]` to the crate attributes to enable
3636

37+
error[E0658]: yield syntax is experimental
38+
--> $DIR/feature-gate-coroutines.rs:5:5
39+
|
40+
LL | yield true;
41+
| ^^^^^^^^^^
42+
|
43+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
44+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
45+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
46+
47+
error[E0658]: yield syntax is experimental
48+
--> $DIR/feature-gate-coroutines.rs:9:16
49+
|
50+
LL | let _ = || yield true;
51+
| ^^^^^^^^^^
52+
|
53+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
54+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
55+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
56+
3757
error[E0627]: yield expression outside of coroutine literal
3858
--> $DIR/feature-gate-coroutines.rs:5:5
3959
|
4060
LL | yield true;
4161
| ^^^^^^^^^^
4262

43-
error: aborting due to 5 previous errors
63+
error: aborting due to 7 previous errors
4464

4565
Some errors have detailed explanations: E0627, E0658.
4666
For more information about an error, try `rustc --explain E0627`.

tests/ui/feature-gates/feature-gate-coroutines.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
//[e2024] compile-flags: --edition 2024 -Zunstable-options
33

44
fn main() {
5-
yield true; //[none]~ ERROR yield syntax is experimental
5+
yield true; //~ ERROR yield syntax is experimental
66
//~^ ERROR yield expression outside of coroutine literal
7+
//[none]~^^ ERROR yield syntax is experimental
78

8-
let _ = || yield true; //[none]~ ERROR yield syntax is experimental
9+
let _ = || yield true; //~ ERROR yield syntax is experimental
10+
//[none]~^ ERROR yield syntax is experimental
911
}
1012

1113
#[cfg(FALSE)]

0 commit comments

Comments
 (0)