Skip to content

Commit 638d2d6

Browse files
committed
Feature gate gen blocks, even in 2024 edition
1 parent c892b28 commit 638d2d6

15 files changed

+101
-15
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,12 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
554554
"consider removing `for<...>`"
555555
);
556556
gate_all!(more_qualified_paths, "usage of qualified paths in this context is experimental");
557-
gate_all!(coroutines, "yield syntax is experimental");
557+
for &span in spans.get(&sym::yield_expr).iter().copied().flatten() {
558+
if !span.at_least_rust_2024() {
559+
gate_feature_post!(&visitor, coroutines, span, "yield syntax is experimental");
560+
}
561+
}
562+
gate_all!(gen_blocks, "gen blocks are experimental");
558563
gate_all!(raw_ref_op, "raw address of syntax is experimental");
559564
gate_all!(const_trait_impl, "const trait impls are experimental");
560565
gate_all!(

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ declare_features! (
456456
(unstable, ffi_returns_twice, "1.34.0", Some(58314), None),
457457
/// Allows using `#[repr(align(...))]` on function items
458458
(unstable, fn_align, "1.53.0", Some(82232), None),
459+
/// Allows defining gen blocks and `gen fn`.
460+
(unstable, gen_blocks, "CURRENT_RUSTC_VERSION", Some(117078), None),
459461
/// Infer generic args for both consts and types.
460462
(unstable, generic_arg_infer, "1.55.0", Some(85077), None),
461463
/// An extension to the `generic_associated_types` feature, allowing incomplete features.

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,7 @@ impl<'a> Parser<'a> {
18501850
let lo = self.prev_token.span;
18511851
let kind = ExprKind::Yield(self.parse_expr_opt()?);
18521852
let span = lo.to(self.prev_token.span);
1853-
self.sess.gated_spans.gate(sym::coroutines, span);
1853+
self.sess.gated_spans.gate(sym::yield_expr, span);
18541854
let expr = self.mk_expr(span, kind);
18551855
self.maybe_recover_from_bad_qpath(expr)
18561856
}
@@ -3075,6 +3075,7 @@ impl<'a> Parser<'a> {
30753075
GenBlockKind::Async
30763076
} else {
30773077
assert!(self.eat_keyword(kw::Gen));
3078+
self.sess.gated_spans.gate(sym::gen_blocks, lo.to(self.token.span));
30783079
GenBlockKind::Gen
30793080
};
30803081
let capture_clause = self.parse_capture_clause()?;

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ symbols! {
819819
future_trait,
820820
gdb_script_file,
821821
ge,
822+
gen_blocks,
822823
gen_future,
823824
gen_kill,
824825
generator_clone,
@@ -1780,6 +1781,7 @@ symbols! {
17801781
xmm_reg,
17811782
yeet_desugar_details,
17821783
yeet_expr,
1784+
yield_expr,
17831785
ymm_reg,
17841786
zmm_reg,
17851787
}

tests/ui/coroutine/gen_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// revisions: e2024 none
22
//[e2024] compile-flags: --edition 2024 -Zunstable-options
3-
#![cfg_attr(e2024, feature(coroutines))]
3+
#![cfg_attr(e2024, feature(gen_blocks))]
44

55
fn main() {
66
let x = gen {};

tests/ui/coroutine/gen_block_is_coro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//compile-flags: --edition 2024 -Zunstable-options
2-
#![feature(coroutines, coroutine_trait)]
2+
#![feature(coroutines, coroutine_trait, gen_blocks)]
33

44
use std::ops::Coroutine;
55

tests/ui/coroutine/gen_block_is_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//compile-flags: --edition 2024 -Zunstable-options
33
//[next] compile-flags: -Ztrait-solver=next
44
// check-pass
5-
#![feature(coroutines)]
5+
#![feature(gen_blocks)]
66

77
fn foo() -> impl Iterator<Item = u32> {
88
gen { yield 42 }

tests/ui/coroutine/gen_block_is_no_future.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//compile-flags: --edition 2024 -Zunstable-options
2-
#![feature(coroutines)]
2+
#![feature(gen_blocks)]
33

44
fn foo() -> impl std::future::Future { //~ ERROR is not a future
55
gen { yield 42 }

tests/ui/coroutine/gen_block_iterate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//compile-flags: --edition 2024 -Zunstable-options
33
//[next] compile-flags: -Ztrait-solver=next
44
// run-pass
5-
#![feature(coroutines)]
5+
#![feature(gen_blocks)]
66

77
fn foo() -> impl Iterator<Item = u32> {
88
gen { yield 42; for x in 3..6 { yield x } }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0627]: yield expression outside of coroutine literal
2+
--> $DIR/feature-gate-coroutines.rs:5:5
3+
|
4+
LL | yield true;
5+
| ^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0627`.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: yield syntax is experimental
2-
--> $DIR/feature-gate-coroutines.rs:2:5
2+
--> $DIR/feature-gate-coroutines.rs:5:5
33
|
44
LL | yield true;
55
| ^^^^^^^^^^
@@ -8,7 +8,16 @@ LL | yield true;
88
= help: add `#![feature(coroutines)]` to the crate attributes to enable
99

1010
error[E0658]: yield syntax is experimental
11-
--> $DIR/feature-gate-coroutines.rs:8:5
11+
--> $DIR/feature-gate-coroutines.rs:8:16
12+
|
13+
LL | let _ = || yield true;
14+
| ^^^^^^^^^^
15+
|
16+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
17+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
18+
19+
error[E0658]: yield syntax is experimental
20+
--> $DIR/feature-gate-coroutines.rs:14:5
1221
|
1322
LL | yield;
1423
| ^^^^^
@@ -17,7 +26,7 @@ LL | yield;
1726
= help: add `#![feature(coroutines)]` to the crate attributes to enable
1827

1928
error[E0658]: yield syntax is experimental
20-
--> $DIR/feature-gate-coroutines.rs:9:5
29+
--> $DIR/feature-gate-coroutines.rs:15:5
2130
|
2231
LL | yield 0;
2332
| ^^^^^^^
@@ -26,12 +35,12 @@ LL | yield 0;
2635
= help: add `#![feature(coroutines)]` to the crate attributes to enable
2736

2837
error[E0627]: yield expression outside of coroutine literal
29-
--> $DIR/feature-gate-coroutines.rs:2:5
38+
--> $DIR/feature-gate-coroutines.rs:5:5
3039
|
3140
LL | yield true;
3241
| ^^^^^^^^^^
3342

34-
error: aborting due to 4 previous errors
43+
error: aborting due to 5 previous errors
3544

3645
Some errors have detailed explanations: E0627, E0658.
3746
For more information about an error, try `rustc --explain E0627`.
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
// revisions: e2024 none
2+
//[e2024] compile-flags: --edition 2024 -Zunstable-options
3+
14
fn main() {
2-
yield true; //~ ERROR yield syntax is experimental
5+
yield true; //[none]~ ERROR yield syntax is experimental
36
//~^ ERROR yield expression outside of coroutine literal
7+
8+
let _ = || yield true; //[none]~ ERROR yield syntax is experimental
49
}
510

611
#[cfg(FALSE)]
712
fn foo() {
8-
yield; //~ ERROR yield syntax is experimental
9-
yield 0; //~ ERROR yield syntax is experimental
13+
// Ok in 2024 edition
14+
yield; //[none]~ ERROR yield syntax is experimental
15+
yield 0; //[none]~ ERROR yield syntax is experimental
1016
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error[E0658]: gen blocks are experimental
2+
--> $DIR/feature-gate-gen_blocks.rs:5:5
3+
|
4+
LL | gen {};
5+
| ^^^^^
6+
|
7+
= note: see issue #117078 <https://github.com/rust-lang/rust/issues/117078> for more information
8+
= help: add `#![feature(gen_blocks)]` to the crate attributes to enable
9+
10+
error[E0658]: gen blocks are experimental
11+
--> $DIR/feature-gate-gen_blocks.rs:13:5
12+
|
13+
LL | gen {};
14+
| ^^^^^
15+
|
16+
= note: see issue #117078 <https://github.com/rust-lang/rust/issues/117078> for more information
17+
= help: add `#![feature(gen_blocks)]` to the crate attributes to enable
18+
19+
error[E0282]: type annotations needed
20+
--> $DIR/feature-gate-gen_blocks.rs:5:9
21+
|
22+
LL | gen {};
23+
| ^^ cannot infer type
24+
25+
error: aborting due to 3 previous errors
26+
27+
Some errors have detailed explanations: E0282, E0658.
28+
For more information about an error, try `rustc --explain E0282`.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0422]: cannot find struct, variant or union type `gen` in this scope
2+
--> $DIR/feature-gate-gen_blocks.rs:5:5
3+
|
4+
LL | gen {};
5+
| ^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0422`.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// revisions: e2024 none
2+
//[e2024] compile-flags: --edition 2024 -Zunstable-options
3+
4+
fn main() {
5+
gen {};
6+
//[none]~^ ERROR: cannot find struct, variant or union type `gen`
7+
//[e2024]~^^ ERROR: gen blocks are experimental
8+
//[e2024]~| ERROR: type annotations needed
9+
}
10+
11+
#[cfg(FALSE)]
12+
fn foo() {
13+
gen {};
14+
//[e2024]~^ ERROR: gen blocks are experimental
15+
}

0 commit comments

Comments
 (0)