Feature gate gen blocks, even in 2024 edition

This commit is contained in:
Oli Scherer 2023-10-23 11:34:27 +00:00
parent c892b28c02
commit 638d2d6fc1
15 changed files with 101 additions and 15 deletions

View File

@ -554,7 +554,12 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
"consider removing `for<...>`" "consider removing `for<...>`"
); );
gate_all!(more_qualified_paths, "usage of qualified paths in this context is experimental"); gate_all!(more_qualified_paths, "usage of qualified paths in this context is experimental");
gate_all!(coroutines, "yield syntax is experimental"); for &span in spans.get(&sym::yield_expr).iter().copied().flatten() {
if !span.at_least_rust_2024() {
gate_feature_post!(&visitor, coroutines, span, "yield syntax is experimental");
}
}
gate_all!(gen_blocks, "gen blocks are experimental");
gate_all!(raw_ref_op, "raw address of syntax is experimental"); gate_all!(raw_ref_op, "raw address of syntax is experimental");
gate_all!(const_trait_impl, "const trait impls are experimental"); gate_all!(const_trait_impl, "const trait impls are experimental");
gate_all!( gate_all!(

View File

@ -456,6 +456,8 @@ declare_features! (
(unstable, ffi_returns_twice, "1.34.0", Some(58314), None), (unstable, ffi_returns_twice, "1.34.0", Some(58314), None),
/// Allows using `#[repr(align(...))]` on function items /// Allows using `#[repr(align(...))]` on function items
(unstable, fn_align, "1.53.0", Some(82232), None), (unstable, fn_align, "1.53.0", Some(82232), None),
/// Allows defining gen blocks and `gen fn`.
(unstable, gen_blocks, "CURRENT_RUSTC_VERSION", Some(117078), None),
/// Infer generic args for both consts and types. /// Infer generic args for both consts and types.
(unstable, generic_arg_infer, "1.55.0", Some(85077), None), (unstable, generic_arg_infer, "1.55.0", Some(85077), None),
/// An extension to the `generic_associated_types` feature, allowing incomplete features. /// An extension to the `generic_associated_types` feature, allowing incomplete features.

View File

@ -1850,7 +1850,7 @@ impl<'a> Parser<'a> {
let lo = self.prev_token.span; let lo = self.prev_token.span;
let kind = ExprKind::Yield(self.parse_expr_opt()?); let kind = ExprKind::Yield(self.parse_expr_opt()?);
let span = lo.to(self.prev_token.span); let span = lo.to(self.prev_token.span);
self.sess.gated_spans.gate(sym::coroutines, span); self.sess.gated_spans.gate(sym::yield_expr, span);
let expr = self.mk_expr(span, kind); let expr = self.mk_expr(span, kind);
self.maybe_recover_from_bad_qpath(expr) self.maybe_recover_from_bad_qpath(expr)
} }
@ -3075,6 +3075,7 @@ impl<'a> Parser<'a> {
GenBlockKind::Async GenBlockKind::Async
} else { } else {
assert!(self.eat_keyword(kw::Gen)); assert!(self.eat_keyword(kw::Gen));
self.sess.gated_spans.gate(sym::gen_blocks, lo.to(self.token.span));
GenBlockKind::Gen GenBlockKind::Gen
}; };
let capture_clause = self.parse_capture_clause()?; let capture_clause = self.parse_capture_clause()?;

View File

@ -819,6 +819,7 @@ symbols! {
future_trait, future_trait,
gdb_script_file, gdb_script_file,
ge, ge,
gen_blocks,
gen_future, gen_future,
gen_kill, gen_kill,
generator_clone, generator_clone,
@ -1780,6 +1781,7 @@ symbols! {
xmm_reg, xmm_reg,
yeet_desugar_details, yeet_desugar_details,
yeet_expr, yeet_expr,
yield_expr,
ymm_reg, ymm_reg,
zmm_reg, zmm_reg,
} }

View File

@ -1,6 +1,6 @@
// revisions: e2024 none // revisions: e2024 none
//[e2024] compile-flags: --edition 2024 -Zunstable-options //[e2024] compile-flags: --edition 2024 -Zunstable-options
#![cfg_attr(e2024, feature(coroutines))] #![cfg_attr(e2024, feature(gen_blocks))]
fn main() { fn main() {
let x = gen {}; let x = gen {};

View File

@ -1,5 +1,5 @@
//compile-flags: --edition 2024 -Zunstable-options //compile-flags: --edition 2024 -Zunstable-options
#![feature(coroutines, coroutine_trait)] #![feature(coroutines, coroutine_trait, gen_blocks)]
use std::ops::Coroutine; use std::ops::Coroutine;

View File

@ -2,7 +2,7 @@
//compile-flags: --edition 2024 -Zunstable-options //compile-flags: --edition 2024 -Zunstable-options
//[next] compile-flags: -Ztrait-solver=next //[next] compile-flags: -Ztrait-solver=next
// check-pass // check-pass
#![feature(coroutines)] #![feature(gen_blocks)]
fn foo() -> impl Iterator<Item = u32> { fn foo() -> impl Iterator<Item = u32> {
gen { yield 42 } gen { yield 42 }

View File

@ -1,5 +1,5 @@
//compile-flags: --edition 2024 -Zunstable-options //compile-flags: --edition 2024 -Zunstable-options
#![feature(coroutines)] #![feature(gen_blocks)]
fn foo() -> impl std::future::Future { //~ ERROR is not a future fn foo() -> impl std::future::Future { //~ ERROR is not a future
gen { yield 42 } gen { yield 42 }

View File

@ -2,7 +2,7 @@
//compile-flags: --edition 2024 -Zunstable-options //compile-flags: --edition 2024 -Zunstable-options
//[next] compile-flags: -Ztrait-solver=next //[next] compile-flags: -Ztrait-solver=next
// run-pass // run-pass
#![feature(coroutines)] #![feature(gen_blocks)]
fn foo() -> impl Iterator<Item = u32> { fn foo() -> impl Iterator<Item = u32> {
gen { yield 42; for x in 3..6 { yield x } } gen { yield 42; for x in 3..6 { yield x } }

View File

@ -0,0 +1,9 @@
error[E0627]: yield expression outside of coroutine literal
--> $DIR/feature-gate-coroutines.rs:5:5
|
LL | yield true;
| ^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0627`.

View File

@ -1,5 +1,5 @@
error[E0658]: yield syntax is experimental error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-coroutines.rs:2:5 --> $DIR/feature-gate-coroutines.rs:5:5
| |
LL | yield true; LL | yield true;
| ^^^^^^^^^^ | ^^^^^^^^^^
@ -8,7 +8,16 @@ LL | yield true;
= help: add `#![feature(coroutines)]` to the crate attributes to enable = help: add `#![feature(coroutines)]` to the crate attributes to enable
error[E0658]: yield syntax is experimental error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-coroutines.rs:8:5 --> $DIR/feature-gate-coroutines.rs:8: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
error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-coroutines.rs:14:5
| |
LL | yield; LL | yield;
| ^^^^^ | ^^^^^
@ -17,7 +26,7 @@ LL | yield;
= help: add `#![feature(coroutines)]` to the crate attributes to enable = help: add `#![feature(coroutines)]` to the crate attributes to enable
error[E0658]: yield syntax is experimental error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-coroutines.rs:9:5 --> $DIR/feature-gate-coroutines.rs:15:5
| |
LL | yield 0; LL | yield 0;
| ^^^^^^^ | ^^^^^^^
@ -26,12 +35,12 @@ LL | yield 0;
= help: add `#![feature(coroutines)]` to the crate attributes to enable = help: add `#![feature(coroutines)]` to the crate attributes to enable
error[E0627]: yield expression outside of coroutine literal error[E0627]: yield expression outside of coroutine literal
--> $DIR/feature-gate-coroutines.rs:2:5 --> $DIR/feature-gate-coroutines.rs:5:5
| |
LL | yield true; LL | yield true;
| ^^^^^^^^^^ | ^^^^^^^^^^
error: aborting due to 4 previous errors error: aborting due to 5 previous errors
Some errors have detailed explanations: E0627, E0658. Some errors have detailed explanations: E0627, E0658.
For more information about an error, try `rustc --explain E0627`. For more information about an error, try `rustc --explain E0627`.

View File

@ -1,10 +1,16 @@
// revisions: e2024 none
//[e2024] compile-flags: --edition 2024 -Zunstable-options
fn main() { fn main() {
yield true; //~ ERROR yield syntax is experimental yield true; //[none]~ ERROR yield syntax is experimental
//~^ ERROR yield expression outside of coroutine literal //~^ ERROR yield expression outside of coroutine literal
let _ = || yield true; //[none]~ ERROR yield syntax is experimental
} }
#[cfg(FALSE)] #[cfg(FALSE)]
fn foo() { fn foo() {
yield; //~ ERROR yield syntax is experimental // Ok in 2024 edition
yield 0; //~ ERROR yield syntax is experimental yield; //[none]~ ERROR yield syntax is experimental
yield 0; //[none]~ ERROR yield syntax is experimental
} }

View File

@ -0,0 +1,28 @@
error[E0658]: gen blocks are experimental
--> $DIR/feature-gate-gen_blocks.rs:5:5
|
LL | gen {};
| ^^^^^
|
= note: see issue #117078 <https://github.com/rust-lang/rust/issues/117078> for more information
= help: add `#![feature(gen_blocks)]` to the crate attributes to enable
error[E0658]: gen blocks are experimental
--> $DIR/feature-gate-gen_blocks.rs:13:5
|
LL | gen {};
| ^^^^^
|
= note: see issue #117078 <https://github.com/rust-lang/rust/issues/117078> for more information
= help: add `#![feature(gen_blocks)]` to the crate attributes to enable
error[E0282]: type annotations needed
--> $DIR/feature-gate-gen_blocks.rs:5:9
|
LL | gen {};
| ^^ cannot infer type
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0282, E0658.
For more information about an error, try `rustc --explain E0282`.

View File

@ -0,0 +1,9 @@
error[E0422]: cannot find struct, variant or union type `gen` in this scope
--> $DIR/feature-gate-gen_blocks.rs:5:5
|
LL | gen {};
| ^^^ not found in this scope
error: aborting due to previous error
For more information about this error, try `rustc --explain E0422`.

View File

@ -0,0 +1,15 @@
// revisions: e2024 none
//[e2024] compile-flags: --edition 2024 -Zunstable-options
fn main() {
gen {};
//[none]~^ ERROR: cannot find struct, variant or union type `gen`
//[e2024]~^^ ERROR: gen blocks are experimental
//[e2024]~| ERROR: type annotations needed
}
#[cfg(FALSE)]
fn foo() {
gen {};
//[e2024]~^ ERROR: gen blocks are experimental
}