Skip to content

Commit f015a2e

Browse files
varkorfanzier
authored andcommitted
Add pre-expansion gating
1 parent ac37e3c commit f015a2e

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
630630
gate_all!(const_trait_impl, "const trait impls are experimental");
631631
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
632632
gate_all!(inline_const, "inline-const is experimental");
633+
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
633634

634635
// All uses of `gate_all!` below this point were added in #65742,
635636
// and subsequently disabled (with the non-early gating readded).

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@ impl<'a> Parser<'a> {
11171117
self.parse_lit_expr(attrs)
11181118
}
11191119
} else if self.eat_keyword(kw::Underscore) {
1120+
self.sess.gated_spans.gate(sym::destructuring_assignment, self.prev_token.span);
11201121
Ok(self.mk_expr(self.prev_token.span, ExprKind::Underscore, attrs))
11211122
} else {
11221123
self.parse_lit_expr(attrs)
@@ -2106,6 +2107,7 @@ impl<'a> Parser<'a> {
21062107
let exp_span = self.prev_token.span;
21072108
// We permit `.. }` on the left-hand side of a destructuring assignment.
21082109
if self.token == token::CloseDelim(token::Brace) {
2110+
self.sess.gated_spans.gate(sym::destructuring_assignment, self.prev_token.span);
21092111
base = StructRest::Rest(self.prev_token.span.shrink_to_hi());
21102112
break;
21112113
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn main() {}
2+
3+
struct S { x : u32 }
4+
5+
#[cfg(FALSE)]
6+
fn foo() {
7+
_; //~ ERROR destructuring assignments are unstable
8+
9+
S { x: 5, .. }; //~ ERROR destructuring assignments are unstable
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0658]: destructuring assignments are unstable
2+
--> $DIR/underscore-range-expr-gating.rs:7:5
3+
|
4+
LL | _;
5+
| ^
6+
|
7+
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
8+
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
9+
10+
error[E0658]: destructuring assignments are unstable
11+
--> $DIR/underscore-range-expr-gating.rs:9:15
12+
|
13+
LL | S { x: 5, .. };
14+
| ^^
15+
|
16+
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
17+
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)