1
Fork 0

Add the yield_expr feature

This commit is contained in:
Eric Holk 2025-03-05 17:09:08 -08:00
parent 30f168ef81
commit 432e1c3eea
No known key found for this signature in database
GPG key ID: F1A772BB658A63E1
9 changed files with 74 additions and 50 deletions

View file

@ -1690,6 +1690,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
let yielded = let yielded =
opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| self.expr_unit(span)); 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 { let is_async_gen = match self.coroutine_kind {
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)) => false, Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)) => false,
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true, Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
@ -1714,28 +1727,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
None, None,
); );
} }
Some(hir::CoroutineKind::Coroutine(_)) => { Some(hir::CoroutineKind::Coroutine(_)) => false,
if !self.tcx.features().coroutines() {
rustc_session::parse::feature_err(
&self.tcx.sess,
sym::coroutines,
span,
fluent_generated::ast_lowering_yield,
)
.emit();
}
false
}
None => { 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()); let suggestion = self.current_item.map(|s| s.shrink_to_lo());
self.dcx().emit_err(YieldInClosure { span, suggestion }); self.dcx().emit_err(YieldInClosure { span, suggestion });
self.coroutine_kind = Some(hir::CoroutineKind::Coroutine(Movability::Movable)); self.coroutine_kind = Some(hir::CoroutineKind::Coroutine(Movability::Movable));

View file

@ -669,6 +669,7 @@ declare_features! (
(unstable, xop_target_feature, "1.81.0", Some(127208)), (unstable, xop_target_feature, "1.81.0", Some(127208)),
/// Allows `do yeet` expressions /// Allows `do yeet` expressions
(unstable, yeet_expr, "1.62.0", Some(96373)), (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. // Features are listed in alphabetical order. Tidy will fail if you don't keep it this way.
// !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! // !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!!

View file

@ -18,16 +18,6 @@ LL | let _ = #[coroutine] || {};
= help: add `#![feature(coroutines)]` to the crate attributes to enable = 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 = 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 error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
--> $DIR/gen_block.rs:16:16 --> $DIR/gen_block.rs:16:16
| |
@ -39,23 +29,13 @@ help: use `#[coroutine]` to make this closure a coroutine
LL | let _ = #[coroutine] || yield true; 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 error[E0282]: type annotations needed
--> $DIR/gen_block.rs:7:13 --> $DIR/gen_block.rs:7:13
| |
LL | let x = gen {}; LL | let x = gen {};
| ^^^^^^ cannot infer type | ^^^^^^ cannot infer type
error: aborting due to 6 previous errors error: aborting due to 4 previous errors
Some errors have detailed explanations: E0282, E0658. Some errors have detailed explanations: E0282, E0658.
For more information about an error, try `rustc --explain E0282`. For more information about an error, try `rustc --explain E0282`.

View file

@ -71,7 +71,7 @@ LL | let _ = || yield true;
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information = 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 = 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 error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
@ -92,7 +92,7 @@ LL | let _ = #[coroutine] || yield true;
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information = 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 = 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 error: aborting due to 11 previous errors

View file

@ -14,12 +14,12 @@ fn main() {
//[none]~^ ERROR: cannot find //[none]~^ ERROR: cannot find
let _ = || yield true; //[none]~ ERROR yield syntax is experimental 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 //~^^ ERROR `yield` can only be used in
let _ = #[coroutine] || yield true; //[none]~ ERROR yield syntax is experimental let _ = #[coroutine] || yield true; //[none]~ ERROR yield syntax is experimental
//~^ ERROR `#[coroutine]` attribute is an experimental feature //~^ ERROR `#[coroutine]` attribute is an experimental feature
//~^^ ERROR yield syntax is experimental //[none]~^^ ERROR yield syntax is experimental
let _ = #[coroutine] || {}; let _ = #[coroutine] || {};
//~^ ERROR `#[coroutine]` attribute is an experimental feature //~^ ERROR `#[coroutine]` attribute is an experimental feature

View file

@ -45,7 +45,7 @@ LL | yield true;
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information = 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 = 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 error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
@ -66,7 +66,7 @@ LL | let _ = || yield true;
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information = 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 = 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 error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks

View file

@ -45,7 +45,7 @@ LL | yield true;
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information = 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 = 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 error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
@ -66,7 +66,7 @@ LL | let _ = || yield true;
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information = 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 = 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 error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks

View file

@ -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
}

View file

@ -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`.