mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Feature gate gen
blocks, even in 2024 edition
This commit is contained in:
parent
c892b28c02
commit
638d2d6fc1
@ -554,7 +554,12 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
|
||||
"consider removing `for<...>`"
|
||||
);
|
||||
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!(const_trait_impl, "const trait impls are experimental");
|
||||
gate_all!(
|
||||
|
@ -456,6 +456,8 @@ declare_features! (
|
||||
(unstable, ffi_returns_twice, "1.34.0", Some(58314), None),
|
||||
/// Allows using `#[repr(align(...))]` on function items
|
||||
(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.
|
||||
(unstable, generic_arg_infer, "1.55.0", Some(85077), None),
|
||||
/// An extension to the `generic_associated_types` feature, allowing incomplete features.
|
||||
|
@ -1850,7 +1850,7 @@ impl<'a> Parser<'a> {
|
||||
let lo = self.prev_token.span;
|
||||
let kind = ExprKind::Yield(self.parse_expr_opt()?);
|
||||
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);
|
||||
self.maybe_recover_from_bad_qpath(expr)
|
||||
}
|
||||
@ -3075,6 +3075,7 @@ impl<'a> Parser<'a> {
|
||||
GenBlockKind::Async
|
||||
} else {
|
||||
assert!(self.eat_keyword(kw::Gen));
|
||||
self.sess.gated_spans.gate(sym::gen_blocks, lo.to(self.token.span));
|
||||
GenBlockKind::Gen
|
||||
};
|
||||
let capture_clause = self.parse_capture_clause()?;
|
||||
|
@ -819,6 +819,7 @@ symbols! {
|
||||
future_trait,
|
||||
gdb_script_file,
|
||||
ge,
|
||||
gen_blocks,
|
||||
gen_future,
|
||||
gen_kill,
|
||||
generator_clone,
|
||||
@ -1780,6 +1781,7 @@ symbols! {
|
||||
xmm_reg,
|
||||
yeet_desugar_details,
|
||||
yeet_expr,
|
||||
yield_expr,
|
||||
ymm_reg,
|
||||
zmm_reg,
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// revisions: e2024 none
|
||||
//[e2024] compile-flags: --edition 2024 -Zunstable-options
|
||||
#![cfg_attr(e2024, feature(coroutines))]
|
||||
#![cfg_attr(e2024, feature(gen_blocks))]
|
||||
|
||||
fn main() {
|
||||
let x = gen {};
|
||||
|
@ -1,5 +1,5 @@
|
||||
//compile-flags: --edition 2024 -Zunstable-options
|
||||
#![feature(coroutines, coroutine_trait)]
|
||||
#![feature(coroutines, coroutine_trait, gen_blocks)]
|
||||
|
||||
use std::ops::Coroutine;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//compile-flags: --edition 2024 -Zunstable-options
|
||||
//[next] compile-flags: -Ztrait-solver=next
|
||||
// check-pass
|
||||
#![feature(coroutines)]
|
||||
#![feature(gen_blocks)]
|
||||
|
||||
fn foo() -> impl Iterator<Item = u32> {
|
||||
gen { yield 42 }
|
||||
|
@ -1,5 +1,5 @@
|
||||
//compile-flags: --edition 2024 -Zunstable-options
|
||||
#![feature(coroutines)]
|
||||
#![feature(gen_blocks)]
|
||||
|
||||
fn foo() -> impl std::future::Future { //~ ERROR is not a future
|
||||
gen { yield 42 }
|
||||
|
@ -2,7 +2,7 @@
|
||||
//compile-flags: --edition 2024 -Zunstable-options
|
||||
//[next] compile-flags: -Ztrait-solver=next
|
||||
// run-pass
|
||||
#![feature(coroutines)]
|
||||
#![feature(gen_blocks)]
|
||||
|
||||
fn foo() -> impl Iterator<Item = u32> {
|
||||
gen { yield 42; for x in 3..6 { yield x } }
|
||||
|
@ -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`.
|
@ -1,5 +1,5 @@
|
||||
error[E0658]: yield syntax is experimental
|
||||
--> $DIR/feature-gate-coroutines.rs:2:5
|
||||
--> $DIR/feature-gate-coroutines.rs:5:5
|
||||
|
|
||||
LL | yield true;
|
||||
| ^^^^^^^^^^
|
||||
@ -8,7 +8,16 @@ LL | yield true;
|
||||
= help: add `#![feature(coroutines)]` to the crate attributes to enable
|
||||
|
||||
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;
|
||||
| ^^^^^
|
||||
@ -17,7 +26,7 @@ LL | yield;
|
||||
= help: add `#![feature(coroutines)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: yield syntax is experimental
|
||||
--> $DIR/feature-gate-coroutines.rs:9:5
|
||||
--> $DIR/feature-gate-coroutines.rs:15:5
|
||||
|
|
||||
LL | yield 0;
|
||||
| ^^^^^^^
|
||||
@ -26,12 +35,12 @@ LL | yield 0;
|
||||
= help: add `#![feature(coroutines)]` to the crate attributes to enable
|
||||
|
||||
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;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0627, E0658.
|
||||
For more information about an error, try `rustc --explain E0627`.
|
@ -1,10 +1,16 @@
|
||||
// revisions: e2024 none
|
||||
//[e2024] compile-flags: --edition 2024 -Zunstable-options
|
||||
|
||||
fn main() {
|
||||
yield true; //~ ERROR yield syntax is experimental
|
||||
yield true; //[none]~ ERROR yield syntax is experimental
|
||||
//~^ ERROR yield expression outside of coroutine literal
|
||||
|
||||
let _ = || yield true; //[none]~ ERROR yield syntax is experimental
|
||||
}
|
||||
|
||||
#[cfg(FALSE)]
|
||||
fn foo() {
|
||||
yield; //~ ERROR yield syntax is experimental
|
||||
yield 0; //~ ERROR yield syntax is experimental
|
||||
// Ok in 2024 edition
|
||||
yield; //[none]~ ERROR yield syntax is experimental
|
||||
yield 0; //[none]~ ERROR yield syntax is experimental
|
||||
}
|
||||
|
28
tests/ui/feature-gates/feature-gate-gen_blocks.e2024.stderr
Normal file
28
tests/ui/feature-gates/feature-gate-gen_blocks.e2024.stderr
Normal 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`.
|
@ -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`.
|
15
tests/ui/feature-gates/feature-gate-gen_blocks.rs
Normal file
15
tests/ui/feature-gates/feature-gate-gen_blocks.rs
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user