Feature gate coroutine yield usage

This commit is contained in:
Oli Scherer 2023-10-23 14:29:00 +00:00
parent 2e5b36741b
commit cece90c65f
7 changed files with 86 additions and 15 deletions

View file

@ -1504,12 +1504,22 @@ fn lower_expr_field(&mut self, f: &ExprField) -> hir::ExprField<'hir> {
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
match self.coroutine_kind {
Some(hir::CoroutineKind::Coroutine) => {}
Some(hir::CoroutineKind::Gen(_)) => {}
Some(hir::CoroutineKind::Async(_)) => {
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span });
}
None => self.coroutine_kind = Some(hir::CoroutineKind::Coroutine),
Some(hir::CoroutineKind::Coroutine) | None => {
if !self.tcx.features().coroutines {
rustc_session::parse::feature_err(
&self.tcx.sess.parse_sess,
sym::coroutines,
span,
"yield syntax is experimental",
)
.emit();
}
self.coroutine_kind = Some(hir::CoroutineKind::Coroutine)
}
}
let expr =

View file

@ -1,9 +1,19 @@
error[E0658]: yield syntax is experimental
--> $DIR/gen_block.rs:15:16
|
LL | let _ = || yield true;
| ^^^^^^^^^^
|
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(coroutines)]` to the crate attributes to enable
error[E0282]: type annotations needed
--> $DIR/gen_block.rs:6:17
|
LL | let x = gen {};
| ^^ cannot infer type
error: aborting due to previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0282`.
Some errors have detailed explanations: E0282, E0658.
For more information about an error, try `rustc --explain E0282`.

View file

@ -25,7 +25,7 @@ LL | gen {};
| ^^^ not found in this scope
error[E0658]: yield syntax is experimental
--> $DIR/gen_block.rs:14:16
--> $DIR/gen_block.rs:15:16
|
LL | let _ = || yield true;
| ^^^^^^^^^^
@ -33,7 +33,17 @@ LL | let _ = || yield true;
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(coroutines)]` to the crate attributes to enable
error: aborting due to 5 previous errors
error[E0658]: yield syntax is experimental
--> $DIR/gen_block.rs:15:16
|
LL | let _ = || yield true;
| ^^^^^^^^^^
|
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(coroutines)]` to the crate attributes to enable
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0422, E0658.
For more information about an error, try `rustc --explain E0422`.

View file

@ -12,6 +12,6 @@ fn main() {
gen {};
//[none]~^ ERROR: cannot find
// FIXME(gen_blocks): should also error in 2024 edition
let _ = || yield true; //[none]~ ERROR yield syntax is experimental
//~^ ERROR yield syntax is experimental
}

View file

@ -1,9 +1,28 @@
error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-coroutines.rs:5:5
|
LL | yield true;
| ^^^^^^^^^^
|
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(coroutines)]` to the crate attributes to enable
error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-coroutines.rs:9:16
|
LL | let _ = || yield true;
| ^^^^^^^^^^
|
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(coroutines)]` to the crate attributes to enable
error[E0627]: yield expression outside of coroutine literal
--> $DIR/feature-gate-coroutines.rs:5:5
|
LL | yield true;
| ^^^^^^^^^^
error: aborting due to previous error
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0627`.
Some errors have detailed explanations: E0627, E0658.
For more information about an error, try `rustc --explain E0627`.

View file

@ -8,7 +8,7 @@ LL | yield true;
= help: add `#![feature(coroutines)]` to the crate attributes to enable
error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-coroutines.rs:8:16
--> $DIR/feature-gate-coroutines.rs:9:16
|
LL | let _ = || yield true;
| ^^^^^^^^^^
@ -17,7 +17,7 @@ LL | let _ = || yield true;
= help: add `#![feature(coroutines)]` to the crate attributes to enable
error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-coroutines.rs:14:5
--> $DIR/feature-gate-coroutines.rs:16:5
|
LL | yield;
| ^^^^^
@ -26,7 +26,7 @@ LL | yield;
= help: add `#![feature(coroutines)]` to the crate attributes to enable
error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-coroutines.rs:15:5
--> $DIR/feature-gate-coroutines.rs:17:5
|
LL | yield 0;
| ^^^^^^^
@ -34,13 +34,33 @@ LL | yield 0;
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(coroutines)]` to the crate attributes to enable
error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-coroutines.rs:5:5
|
LL | yield true;
| ^^^^^^^^^^
|
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(coroutines)]` to the crate attributes to enable
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-coroutines.rs:9:16
|
LL | let _ = || yield true;
| ^^^^^^^^^^
|
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(coroutines)]` to the crate attributes to enable
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0627]: yield expression outside of coroutine literal
--> $DIR/feature-gate-coroutines.rs:5:5
|
LL | yield true;
| ^^^^^^^^^^
error: aborting due to 5 previous errors
error: aborting due to 7 previous errors
Some errors have detailed explanations: E0627, E0658.
For more information about an error, try `rustc --explain E0627`.

View file

@ -2,10 +2,12 @@
//[e2024] compile-flags: --edition 2024 -Zunstable-options
fn main() {
yield true; //[none]~ ERROR yield syntax is experimental
yield true; //~ ERROR yield syntax is experimental
//~^ ERROR yield expression outside of coroutine literal
//[none]~^^ ERROR yield syntax is experimental
let _ = || yield true; //[none]~ ERROR yield syntax is experimental
let _ = || yield true; //~ ERROR yield syntax is experimental
//[none]~^ ERROR yield syntax is experimental
}
#[cfg(FALSE)]