Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move yield expressions behind their own feature gate #138081

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
let yielded =
opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| self.expr_unit(span));

if !self.tcx.features().yield_expr()
&& !self.tcx.features().coroutines()
&& !self.tcx.features().gen_blocks()
{
rustc_session::parse::feature_err(
&self.tcx.sess,
sym::yield_expr,
span,
fluent_generated::ast_lowering_yield,
)
.emit();
}

let is_async_gen = match self.coroutine_kind {
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)) => false,
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
Expand All @@ -1714,28 +1727,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
None,
);
}
Some(hir::CoroutineKind::Coroutine(_)) => {
if !self.tcx.features().coroutines() {
rustc_session::parse::feature_err(
&self.tcx.sess,
sym::coroutines,
span,
fluent_generated::ast_lowering_yield,
)
.emit();
}
false
}
Some(hir::CoroutineKind::Coroutine(_)) => false,
None => {
if !self.tcx.features().coroutines() {
rustc_session::parse::feature_err(
&self.tcx.sess,
sym::coroutines,
span,
fluent_generated::ast_lowering_yield,
)
.emit();
}
let suggestion = self.current_item.map(|s| s.shrink_to_lo());
self.dcx().emit_err(YieldInClosure { span, suggestion });
self.coroutine_kind = Some(hir::CoroutineKind::Coroutine(Movability::Movable));
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ declare_features! (
(unstable, xop_target_feature, "1.81.0", Some(127208)),
/// Allows `do yeet` expressions
(unstable, yeet_expr, "1.62.0", Some(96373)),
(unstable, yield_expr, "CURRENT_RUSTC_VERSION", Some(43122)),
// !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!!
// Features are listed in alphabetical order. Tidy will fail if you don't keep it this way.
// !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!!
Expand Down
22 changes: 1 addition & 21 deletions tests/ui/coroutine/gen_block.e2024.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ LL | let _ = #[coroutine] || {};
= help: add `#![feature(coroutines)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: yield syntax is experimental
--> $DIR/gen_block.rs:16: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: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
--> $DIR/gen_block.rs:16:16
|
Expand All @@ -39,23 +29,13 @@ help: use `#[coroutine]` to make this closure a coroutine
LL | let _ = #[coroutine] || yield true;
| ++++++++++++

error[E0658]: yield syntax is experimental
--> $DIR/gen_block.rs:20:29
|
LL | let _ = #[coroutine] || 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: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0282]: type annotations needed
--> $DIR/gen_block.rs:7:13
|
LL | let x = gen {};
| ^^^^^^ cannot infer type

error: aborting due to 6 previous errors
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0282, E0658.
For more information about an error, try `rustc --explain E0282`.
4 changes: 2 additions & 2 deletions tests/ui/coroutine/gen_block.none.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ 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
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
Expand All @@ -92,7 +92,7 @@ LL | let _ = #[coroutine] || 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
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 11 previous errors
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/coroutine/gen_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ fn main() {
//[none]~^ ERROR: cannot find

let _ = || yield true; //[none]~ ERROR yield syntax is experimental
//~^ ERROR yield syntax is experimental
//[none]~^ ERROR yield syntax is experimental
//~^^ ERROR `yield` can only be used in

let _ = #[coroutine] || yield true; //[none]~ ERROR yield syntax is experimental
//~^ ERROR `#[coroutine]` attribute is an experimental feature
//~^^ ERROR yield syntax is experimental
//[none]~^^ ERROR yield syntax is experimental

let _ = #[coroutine] || {};
//~^ ERROR `#[coroutine]` attribute is an experimental feature
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/feature-gates/feature-gate-coroutines.e2024.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ 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
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
Expand All @@ -66,7 +66,7 @@ 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
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/feature-gates/feature-gate-coroutines.none.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ 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
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
Expand All @@ -66,7 +66,7 @@ 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
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/feature-gates/feature-gate-yield-expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ edition: 2024
#![feature(stmt_expr_attributes)]

fn main() {
yield (); //~ ERROR yield syntax is experimental
//~^ ERROR yield syntax is experimental
//~^^ ERROR `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
//~^^^ ERROR yield expression outside of coroutine literal
}
41 changes: 41 additions & 0 deletions tests/ui/feature-gates/feature-gate-yield-expr.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-yield-expr.rs:5:5
|
LL | yield ();
| ^^^^^^^^
|
= 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: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-yield-expr.rs:5:5
|
LL | yield ();
| ^^^^^^^^
|
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
--> $DIR/feature-gate-yield-expr.rs:5:5
|
LL | yield ();
| ^^^^^^^^
|
help: use `#[coroutine]` to make this closure a coroutine
|
LL | #[coroutine] fn main() {
| ++++++++++++

error[E0627]: yield expression outside of coroutine literal
--> $DIR/feature-gate-yield-expr.rs:5:5
|
LL | yield ();
| ^^^^^^^^

error: aborting due to 4 previous errors

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