mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Rollup merge of #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.
This commit is contained in:
commit
1dd975beb3
@ -523,9 +523,18 @@ 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");
|
||||||
for &span in spans.get(&sym::yield_expr).iter().copied().flatten() {
|
// yield can be enabled either by `coroutines` or `gen_blocks`
|
||||||
if !span.at_least_rust_2024() {
|
if let Some(spans) = spans.get(&sym::yield_expr) {
|
||||||
gate!(&visitor, coroutines, span, "yield syntax is experimental");
|
for span in spans {
|
||||||
|
if (!visitor.features.coroutines() && !span.allows_unstable(sym::coroutines))
|
||||||
|
&& (!visitor.features.gen_blocks() && !span.allows_unstable(sym::gen_blocks))
|
||||||
|
{
|
||||||
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
|
// Don't know which of the two features to include in the
|
||||||
|
// error message, so I am arbitrarily picking one.
|
||||||
|
feature_err(&visitor.sess, sym::coroutines, *span, "yield syntax is experimental")
|
||||||
|
.emit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gate_all!(gen_blocks, "gen blocks are experimental");
|
gate_all!(gen_blocks, "gen blocks are experimental");
|
||||||
|
@ -8,6 +8,46 @@ LL | yield true;
|
|||||||
= help: add `#![feature(coroutines)]` to the crate attributes to enable
|
= help: add `#![feature(coroutines)]` to the crate attributes to enable
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
|
error[E0658]: yield syntax is experimental
|
||||||
|
--> $DIR/feature-gate-coroutines.rs:10: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
|
||||||
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
|
error[E0658]: yield syntax is experimental
|
||||||
|
--> $DIR/feature-gate-coroutines.rs:18:5
|
||||||
|
|
|
||||||
|
LL | yield;
|
||||||
|
| ^^^^^
|
||||||
|
|
|
||||||
|
= 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
|
||||||
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
|
error[E0658]: yield syntax is experimental
|
||||||
|
--> $DIR/feature-gate-coroutines.rs:19:5
|
||||||
|
|
|
||||||
|
LL | yield 0;
|
||||||
|
| ^^^^^^^
|
||||||
|
|
|
||||||
|
= 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
|
||||||
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
|
error[E0658]: yield syntax is experimental
|
||||||
|
--> $DIR/feature-gate-coroutines.rs:5:5
|
||||||
|
|
|
||||||
|
LL | 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
|
||||||
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
|
error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
|
||||||
--> $DIR/feature-gate-coroutines.rs:5:5
|
--> $DIR/feature-gate-coroutines.rs:5:5
|
||||||
|
|
|
|
||||||
@ -46,7 +86,7 @@ error[E0627]: yield expression outside of coroutine literal
|
|||||||
LL | yield true;
|
LL | yield true;
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 9 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`.
|
||||||
|
@ -4,17 +4,17 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
yield true; //~ ERROR yield syntax is experimental
|
yield true; //~ ERROR yield syntax is experimental
|
||||||
//~^ ERROR yield expression outside of coroutine literal
|
//~^ ERROR yield expression outside of coroutine literal
|
||||||
//[none]~^^ ERROR yield syntax is experimental
|
//~^^ ERROR yield syntax is experimental
|
||||||
//~^^^ ERROR `yield` can only be used
|
//~^^^ ERROR `yield` can only be used
|
||||||
|
|
||||||
let _ = || yield true; //~ ERROR yield syntax is experimental
|
let _ = || yield true; //~ ERROR yield syntax is experimental
|
||||||
//[none]~^ ERROR yield syntax is experimental
|
//~^ ERROR yield syntax is experimental
|
||||||
//~^^ ERROR `yield` can only be used
|
//~^^ ERROR `yield` can only be used
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(FALSE)]
|
#[cfg(FALSE)]
|
||||||
fn foo() {
|
fn foo() {
|
||||||
// Ok in 2024 edition
|
// Ok in 2024 edition
|
||||||
yield; //[none]~ ERROR yield syntax is experimental
|
yield; //~ ERROR yield syntax is experimental
|
||||||
yield 0; //[none]~ ERROR yield syntax is experimental
|
yield 0; //~ ERROR yield syntax is experimental
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user