Skip to content

Commit 2aff6b3

Browse files
committed
pre-expansion gate box_patterns
1 parent 1f470ce commit 2aff6b3

File tree

7 files changed

+23
-16
lines changed

7 files changed

+23
-16
lines changed

src/libsyntax/feature_gate/check.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
510510
visit::walk_expr(self, e)
511511
}
512512

513-
fn visit_arm(&mut self, arm: &'a ast::Arm) {
514-
visit::walk_arm(self, arm)
515-
}
516-
517513
fn visit_pat(&mut self, pattern: &'a ast::Pat) {
518514
match &pattern.kind {
519515
PatKind::Slice(pats) => {
@@ -533,11 +529,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
533529
}
534530
}
535531
}
536-
PatKind::Box(..) => {
537-
gate_feature_post!(&self, box_patterns,
538-
pattern.span,
539-
"box pattern syntax is experimental");
540-
}
541532
PatKind::Range(_, _, Spanned { node: RangeEnd::Excluded, .. }) => {
542533
gate_feature_post!(&self, exclusive_range_pattern, pattern.span,
543534
"exclusive range pattern syntax is experimental");
@@ -547,11 +538,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
547538
visit::walk_pat(self, pattern)
548539
}
549540

550-
fn visit_fn(&mut self,
551-
fn_kind: FnKind<'a>,
552-
fn_decl: &'a ast::FnDecl,
553-
span: Span,
554-
_node_id: NodeId) {
541+
fn visit_fn(&mut self, fn_kind: FnKind<'a>, fn_decl: &'a ast::FnDecl, span: Span, _: NodeId) {
555542
if let Some(header) = fn_kind.header() {
556543
// Stability of const fn methods are covered in
557544
// `visit_trait_item` and `visit_impl_item` below; this is
@@ -827,6 +814,7 @@ pub fn check_crate(krate: &ast::Crate,
827814
gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");
828815
gate_all!(const_generics, "const generics are unstable");
829816
gate_all!(decl_macro, "`macro` is experimental");
817+
gate_all!(box_patterns, "box pattern syntax is experimental");
830818

831819
visit::walk_crate(&mut visitor, krate);
832820
}

src/libsyntax/parse/parser/pat.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ impl<'a> Parser<'a> {
324324
self.parse_pat_ident(BindingMode::ByRef(mutbl))?
325325
} else if self.eat_keyword(kw::Box) {
326326
// Parse `box pat`
327-
PatKind::Box(self.parse_pat_with_range_pat(false, None)?)
327+
let pat = self.parse_pat_with_range_pat(false, None)?;
328+
self.sess.gated_spans.box_patterns.borrow_mut().push(lo.to(self.prev_span));
329+
PatKind::Box(pat)
328330
} else if self.can_be_ident_pat() {
329331
// Parse `ident @ pat`
330332
// This can give false positives and parse nullary enums,

src/libsyntax/sess.rs

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ crate struct GatedSpans {
4040
pub const_generics: Lock<Vec<Span>>,
4141
/// Spans collected for gating `decl_macro`, e.g. `macro m() {}`.
4242
pub decl_macro: Lock<Vec<Span>>,
43+
/// Spans collected for gating `box_patterns`, e.g. `box 0`.
44+
pub box_patterns: Lock<Vec<Span>>,
4345
}
4446

4547
/// Info about a parsing session.

src/test/ui/feature-gates/feature-gate-box_patterns.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ fn main() {
22
let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental
33
println!("x: {}", x);
44
}
5+
6+
macro_rules! accept_pat { ($p:pat) => {} }
7+
accept_pat!(box 0); //~ ERROR box pattern syntax is experimental

src/test/ui/feature-gates/feature-gate-box_patterns.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ LL | let box x = Box::new('c');
77
= note: for more information, see https://github.com/rust-lang/rust/issues/29641
88
= help: add `#![feature(box_patterns)]` to the crate attributes to enable
99

10-
error: aborting due to previous error
10+
error[E0658]: box pattern syntax is experimental
11+
--> $DIR/feature-gate-box_patterns.rs:7:13
12+
|
13+
LL | accept_pat!(box 0);
14+
| ^^^^^
15+
|
16+
= note: for more information, see https://github.com/rust-lang/rust/issues/29641
17+
= help: add `#![feature(box_patterns)]` to the crate attributes to enable
18+
19+
error: aborting due to 2 previous errors
1120

1221
For more information about this error, try `rustc --explain E0658`.

src/test/ui/or-patterns/or-patterns-syntactic-pass.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// check-pass
55

66
#![feature(or_patterns)]
7+
#![feature(box_patterns)]
78

89
fn main() {}
910

src/test/ui/pattern/rest-pat-syntactic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
// check-pass
55

6+
#![feature(box_patterns)]
7+
68
fn main() {}
79

810
macro_rules! accept_pat {

0 commit comments

Comments
 (0)