Skip to content

Commit f1133fc

Browse files
authored
Unrolled build for rust-lang#132668
Rollup merge of rust-lang#132668 - ehuss:yield-gate-2024, r=davidtwco Feature gate yield expressions not in 2024 This changes it so that yield expressions are no longer allowed in the 2024 edition without a feature gate. We are currently only reserving the `gen` keyword in the 2024 edition, and not allowing anything else to be implicitly enabled by the edition. In practice this doesn't have a significant difference since yield expressions can't really be used outside of coroutines or gen blocks, which have their own feature gates. However, it does affect what is accepted pre-expansion, and I would feel more comfortable not allowing yield expressions. I believe the stabilization process for gen blocks or coroutines will not need to check the edition here, so this shouldn't ever be needed.
2 parents 9a9dadd + e04acff commit f1133fc

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,18 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
523523
"consider removing `for<...>`"
524524
);
525525
gate_all!(more_qualified_paths, "usage of qualified paths in this context is experimental");
526-
for &span in spans.get(&sym::yield_expr).iter().copied().flatten() {
527-
if !span.at_least_rust_2024() {
528-
gate!(&visitor, coroutines, span, "yield syntax is experimental");
526+
// yield can be enabled either by `coroutines` or `gen_blocks`
527+
if let Some(spans) = spans.get(&sym::yield_expr) {
528+
for span in spans {
529+
if (!visitor.features.coroutines() && !span.allows_unstable(sym::coroutines))
530+
&& (!visitor.features.gen_blocks() && !span.allows_unstable(sym::gen_blocks))
531+
{
532+
#[allow(rustc::untranslatable_diagnostic)]
533+
// Don't know which of the two features to include in the
534+
// error message, so I am arbitrarily picking one.
535+
feature_err(&visitor.sess, sym::coroutines, *span, "yield syntax is experimental")
536+
.emit();
537+
}
529538
}
530539
}
531540
gate_all!(gen_blocks, "gen blocks are experimental");

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

+41-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,46 @@ LL | yield true;
88
= help: add `#![feature(coroutines)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

11+
error[E0658]: yield syntax is experimental
12+
--> $DIR/feature-gate-coroutines.rs:10:16
13+
|
14+
LL | let _ = || yield true;
15+
| ^^^^^^^^^^
16+
|
17+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
18+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
21+
error[E0658]: yield syntax is experimental
22+
--> $DIR/feature-gate-coroutines.rs:18:5
23+
|
24+
LL | yield;
25+
| ^^^^^
26+
|
27+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
28+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30+
31+
error[E0658]: yield syntax is experimental
32+
--> $DIR/feature-gate-coroutines.rs:19:5
33+
|
34+
LL | yield 0;
35+
| ^^^^^^^
36+
|
37+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
38+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
39+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
40+
41+
error[E0658]: yield syntax is experimental
42+
--> $DIR/feature-gate-coroutines.rs:5:5
43+
|
44+
LL | yield true;
45+
| ^^^^^^^^^^
46+
|
47+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
48+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
49+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
50+
1151
error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
1252
--> $DIR/feature-gate-coroutines.rs:5:5
1353
|
@@ -46,7 +86,7 @@ error[E0627]: yield expression outside of coroutine literal
4686
LL | yield true;
4787
| ^^^^^^^^^^
4888

49-
error: aborting due to 5 previous errors
89+
error: aborting due to 9 previous errors
5090

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

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
fn main() {
55
yield true; //~ ERROR yield syntax is experimental
66
//~^ ERROR yield expression outside of coroutine literal
7-
//[none]~^^ ERROR yield syntax is experimental
7+
//~^^ ERROR yield syntax is experimental
88
//~^^^ ERROR `yield` can only be used
99

1010
let _ = || yield true; //~ ERROR yield syntax is experimental
11-
//[none]~^ ERROR yield syntax is experimental
11+
//~^ ERROR yield syntax is experimental
1212
//~^^ ERROR `yield` can only be used
1313
}
1414

1515
#[cfg(FALSE)]
1616
fn foo() {
1717
// Ok in 2024 edition
18-
yield; //[none]~ ERROR yield syntax is experimental
19-
yield 0; //[none]~ ERROR yield syntax is experimental
18+
yield; //~ ERROR yield syntax is experimental
19+
yield 0; //~ ERROR yield syntax is experimental
2020
}

0 commit comments

Comments
 (0)