Skip to content

Commit db0c825

Browse files
Gate static coroutines behind a parser feature
1 parent 0330525 commit db0c825

File tree

10 files changed

+67
-24
lines changed

10 files changed

+67
-24
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
525525
gate_all!(where_clause_attrs, "attributes in `where` clause are unstable");
526526
gate_all!(super_let, "`super let` is experimental");
527527
gate_all!(frontmatter, "frontmatters are experimental");
528+
gate_all!(coroutines, "coroutine syntax is experimental");
528529

529530
if !visitor.features.never_patterns() {
530531
if let Some(spans) = spans.get(&sym::never_patterns) {

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,8 +2401,12 @@ impl<'a> Parser<'a> {
24012401

24022402
let constness = self.parse_closure_constness();
24032403

2404-
let movability =
2405-
if self.eat_keyword(exp!(Static)) { Movability::Static } else { Movability::Movable };
2404+
let movability = if self.eat_keyword(exp!(Static)) {
2405+
self.psess.gated_spans.gate(sym::coroutines, self.prev_token.span);
2406+
Movability::Static
2407+
} else {
2408+
Movability::Movable
2409+
};
24062410

24072411
let coroutine_kind = if self.token_uninterpolated_span().at_least_rust_2018() {
24082412
self.parse_coroutine_kind(Case::Sensitive)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Tests that static closures are not stable in the parser grammar unless the
2+
// coroutine feature is enabled.
3+
4+
#[cfg(any())]
5+
fn foo() {
6+
let _ = static || {};
7+
//~^ ERROR coroutine syntax is experimental
8+
}
9+
10+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: coroutine syntax is experimental
2+
--> $DIR/static-closure-unexpanded.rs:6:13
3+
|
4+
LL | let _ = static || {};
5+
| ^^^^^^
6+
|
7+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
8+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.

tests/ui/static/static-closures.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
fn main() {
22
static || {};
33
//~^ ERROR closures cannot be static
4+
//~| ERROR coroutine syntax is experimental
45
}
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
error[E0658]: coroutine syntax is experimental
2+
--> $DIR/static-closures.rs:2:5
3+
|
4+
LL | static || {};
5+
| ^^^^^^
6+
|
7+
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
8+
= help: add `#![feature(coroutines)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
111
error[E0697]: closures cannot be static
212
--> $DIR/static-closures.rs:2:5
313
|
414
LL | static || {};
515
| ^^^^^^^^^
616

7-
error: aborting due to 1 previous error
17+
error: aborting due to 2 previous errors
818

9-
For more information about this error, try `rustc --explain E0697`.
19+
Some errors have detailed explanations: E0658, E0697.
20+
For more information about an error, try `rustc --explain E0658`.

tests/ui/unpretty/exhaustive.expanded.stdout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(box_patterns)]
1414
#![feature(builtin_syntax)]
1515
#![feature(const_trait_impl)]
16+
#![feature(coroutines)]
1617
#![feature(decl_macro)]
1718
#![feature(deref_patterns)]
1819
#![feature(explicit_tail_calls)]

tests/ui/unpretty/exhaustive.hir.stderr

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error[E0697]: closures cannot be static
2-
--> $DIR/exhaustive.rs:209:9
2+
--> $DIR/exhaustive.rs:210:9
33
|
44
LL | static || value;
55
| ^^^^^^^^^
66

77
error[E0697]: closures cannot be static
8-
--> $DIR/exhaustive.rs:210:9
8+
--> $DIR/exhaustive.rs:211:9
99
|
1010
LL | static move || value;
1111
| ^^^^^^^^^^^^^^
1212

1313
error[E0728]: `await` is only allowed inside `async` functions and blocks
14-
--> $DIR/exhaustive.rs:239:13
14+
--> $DIR/exhaustive.rs:240:13
1515
|
1616
LL | fn expr_await() {
1717
| --------------- this is not `async`
@@ -20,19 +20,19 @@ LL | fut.await;
2020
| ^^^^^ only allowed inside `async` functions and blocks
2121

2222
error: in expressions, `_` can only be used on the left-hand side of an assignment
23-
--> $DIR/exhaustive.rs:288:9
23+
--> $DIR/exhaustive.rs:289:9
2424
|
2525
LL | _;
2626
| ^ `_` not allowed here
2727

2828
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
29-
--> $DIR/exhaustive.rs:298:9
29+
--> $DIR/exhaustive.rs:299:9
3030
|
3131
LL | x::();
3232
| ^^^^^ only `Fn` traits may use parentheses
3333

3434
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
35-
--> $DIR/exhaustive.rs:299:9
35+
--> $DIR/exhaustive.rs:300:9
3636
|
3737
LL | x::(T, T) -> T;
3838
| ^^^^^^^^^^^^^^ only `Fn` traits may use parentheses
@@ -44,31 +44,31 @@ LL + x::<T, T> -> T;
4444
|
4545

4646
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
47-
--> $DIR/exhaustive.rs:300:9
47+
--> $DIR/exhaustive.rs:301:9
4848
|
4949
LL | crate::() -> ()::expressions::() -> ()::expr_path;
5050
| ^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses
5151

5252
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
53-
--> $DIR/exhaustive.rs:300:26
53+
--> $DIR/exhaustive.rs:301:26
5454
|
5555
LL | crate::() -> ()::expressions::() -> ()::expr_path;
5656
| ^^^^^^^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses
5757

5858
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
59-
--> $DIR/exhaustive.rs:303:9
59+
--> $DIR/exhaustive.rs:304:9
6060
|
6161
LL | core::()::marker::()::PhantomData;
6262
| ^^^^^^^^ only `Fn` traits may use parentheses
6363

6464
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
65-
--> $DIR/exhaustive.rs:303:19
65+
--> $DIR/exhaustive.rs:304:19
6666
|
6767
LL | core::()::marker::()::PhantomData;
6868
| ^^^^^^^^^^ only `Fn` traits may use parentheses
6969

7070
error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
71-
--> $DIR/exhaustive.rs:390:9
71+
--> $DIR/exhaustive.rs:391:9
7272
|
7373
LL | yield;
7474
| ^^^^^
@@ -79,29 +79,29 @@ LL | #[coroutine] fn expr_yield() {
7979
| ++++++++++++
8080

8181
error[E0703]: invalid ABI: found `C++`
82-
--> $DIR/exhaustive.rs:470:23
82+
--> $DIR/exhaustive.rs:471:23
8383
|
8484
LL | unsafe extern "C++" {}
8585
| ^^^^^ invalid ABI
8686
|
8787
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
8888

8989
error: `..` patterns are not allowed here
90-
--> $DIR/exhaustive.rs:677:13
90+
--> $DIR/exhaustive.rs:678:13
9191
|
9292
LL | let ..;
9393
| ^^
9494
|
9595
= note: only allowed in tuple, tuple struct, and slice patterns
9696

9797
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
98-
--> $DIR/exhaustive.rs:792:16
98+
--> $DIR/exhaustive.rs:793:16
9999
|
100100
LL | let _: T() -> !;
101101
| ^^^^^^^^ only `Fn` traits may use parentheses
102102

103103
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
104-
--> $DIR/exhaustive.rs:806:16
104+
--> $DIR/exhaustive.rs:807:16
105105
|
106106
LL | let _: impl Send;
107107
| ^^^^^^^^^
@@ -112,7 +112,7 @@ LL | let _: impl Send;
112112
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
113113

114114
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
115-
--> $DIR/exhaustive.rs:807:16
115+
--> $DIR/exhaustive.rs:808:16
116116
|
117117
LL | let _: impl Send + 'static;
118118
| ^^^^^^^^^^^^^^^^^^^
@@ -123,7 +123,7 @@ LL | let _: impl Send + 'static;
123123
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
124124

125125
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
126-
--> $DIR/exhaustive.rs:808:16
126+
--> $DIR/exhaustive.rs:809:16
127127
|
128128
LL | let _: impl 'static + Send;
129129
| ^^^^^^^^^^^^^^^^^^^
@@ -134,7 +134,7 @@ LL | let _: impl 'static + Send;
134134
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
135135

136136
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
137-
--> $DIR/exhaustive.rs:809:16
137+
--> $DIR/exhaustive.rs:810:16
138138
|
139139
LL | let _: impl ?Sized;
140140
| ^^^^^^^^^^^
@@ -145,7 +145,7 @@ LL | let _: impl ?Sized;
145145
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
146146

147147
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
148-
--> $DIR/exhaustive.rs:810:16
148+
--> $DIR/exhaustive.rs:811:16
149149
|
150150
LL | let _: impl [const] Clone;
151151
| ^^^^^^^^^^^^^^^^^^
@@ -156,7 +156,7 @@ LL | let _: impl [const] Clone;
156156
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
157157

158158
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
159-
--> $DIR/exhaustive.rs:811:16
159+
--> $DIR/exhaustive.rs:812:16
160160
|
161161
LL | let _: impl for<'a> Send;
162162
| ^^^^^^^^^^^^^^^^^

tests/ui/unpretty/exhaustive.hir.stdout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![feature(box_patterns)]
1313
#![feature(builtin_syntax)]
1414
#![feature(const_trait_impl)]
15+
#![feature(coroutines)]
1516
#![feature(decl_macro)]
1617
#![feature(deref_patterns)]
1718
#![feature(explicit_tail_calls)]

tests/ui/unpretty/exhaustive.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![feature(box_patterns)]
1313
#![feature(builtin_syntax)]
1414
#![feature(const_trait_impl)]
15+
#![feature(coroutines)]
1516
#![feature(decl_macro)]
1617
#![feature(deref_patterns)]
1718
#![feature(explicit_tail_calls)]

0 commit comments

Comments
 (0)