Skip to content

Commit 5ae4d9b

Browse files
committed
Add the minimum needed for a yield_expr feature
1 parent 30f168e commit 5ae4d9b

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+11-21
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
16901690
let yielded =
16911691
opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| self.expr_unit(span));
16921692

1693+
if !self.tcx.features().yield_expr() {
1694+
rustc_session::parse::feature_err(
1695+
&self.tcx.sess,
1696+
sym::yield_expr,
1697+
span,
1698+
fluent_generated::ast_lowering_yield,
1699+
)
1700+
.emit();
1701+
}
1702+
16931703
let is_async_gen = match self.coroutine_kind {
16941704
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)) => false,
16951705
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
@@ -1714,28 +1724,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
17141724
None,
17151725
);
17161726
}
1717-
Some(hir::CoroutineKind::Coroutine(_)) => {
1718-
if !self.tcx.features().coroutines() {
1719-
rustc_session::parse::feature_err(
1720-
&self.tcx.sess,
1721-
sym::coroutines,
1722-
span,
1723-
fluent_generated::ast_lowering_yield,
1724-
)
1725-
.emit();
1726-
}
1727-
false
1728-
}
1727+
Some(hir::CoroutineKind::Coroutine(_)) => false,
17291728
None => {
1730-
if !self.tcx.features().coroutines() {
1731-
rustc_session::parse::feature_err(
1732-
&self.tcx.sess,
1733-
sym::coroutines,
1734-
span,
1735-
fluent_generated::ast_lowering_yield,
1736-
)
1737-
.emit();
1738-
}
17391729
let suggestion = self.current_item.map(|s| s.shrink_to_lo());
17401730
self.dcx().emit_err(YieldInClosure { span, suggestion });
17411731
self.coroutine_kind = Some(hir::CoroutineKind::Coroutine(Movability::Movable));

compiler/rustc_feature/src/unstable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ declare_features! (
669669
(unstable, xop_target_feature, "1.81.0", Some(127208)),
670670
/// Allows `do yeet` expressions
671671
(unstable, yeet_expr, "1.62.0", Some(96373)),
672+
(unstable, yield_expr, "CURRENT_RUSTC_VERSION", Some(43122)),
672673
// !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!!
673674
// Features are listed in alphabetical order. Tidy will fail if you don't keep it this way.
674675
// !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ edition: 2024
2+
#![feature(coroutines, stmt_expr_attributes)]
3+
4+
fn main() {
5+
let _ = #[coroutine] || {
6+
yield ();
7+
//~^ ERROR yield syntax is experimental
8+
};
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: yield syntax is experimental
2+
--> $DIR/feature-gate-yield-expr.rs:6:9
3+
|
4+
LL | yield ();
5+
| ^^^^^^^^
6+
|
7+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
8+
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)