]> git.lizzy.rs Git - rust.git/commitdiff
pre-expansion gate box_patterns
authorMazdak Farrokhzad <twingoow@gmail.com>
Sat, 21 Sep 2019 17:49:54 +0000 (19:49 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Wed, 23 Oct 2019 22:32:03 +0000 (00:32 +0200)
src/libsyntax/feature_gate/check.rs
src/libsyntax/parse/parser/pat.rs
src/libsyntax/sess.rs
src/test/ui/feature-gates/feature-gate-box_patterns.rs
src/test/ui/feature-gates/feature-gate-box_patterns.stderr
src/test/ui/or-patterns/or-patterns-syntactic-pass.rs
src/test/ui/pattern/rest-pat-syntactic.rs

index 9882db4e3f30880d192bf9f7333a5146edf5efc0..7c4668122a4c2e6b219ff917b647739513a7d7df 100644 (file)
@@ -510,10 +510,6 @@ fn visit_expr(&mut self, e: &'a ast::Expr) {
         visit::walk_expr(self, e)
     }
 
-    fn visit_arm(&mut self, arm: &'a ast::Arm) {
-        visit::walk_arm(self, arm)
-    }
-
     fn visit_pat(&mut self, pattern: &'a ast::Pat) {
         match &pattern.kind {
             PatKind::Slice(pats) => {
@@ -533,11 +529,6 @@ fn visit_pat(&mut self, pattern: &'a ast::Pat) {
                     }
                 }
             }
-            PatKind::Box(..) => {
-                gate_feature_post!(&self, box_patterns,
-                                  pattern.span,
-                                  "box pattern syntax is experimental");
-            }
             PatKind::Range(_, _, Spanned { node: RangeEnd::Excluded, .. }) => {
                 gate_feature_post!(&self, exclusive_range_pattern, pattern.span,
                                    "exclusive range pattern syntax is experimental");
@@ -547,11 +538,7 @@ fn visit_pat(&mut self, pattern: &'a ast::Pat) {
         visit::walk_pat(self, pattern)
     }
 
-    fn visit_fn(&mut self,
-                fn_kind: FnKind<'a>,
-                fn_decl: &'a ast::FnDecl,
-                span: Span,
-                _node_id: NodeId) {
+    fn visit_fn(&mut self, fn_kind: FnKind<'a>, fn_decl: &'a ast::FnDecl, span: Span, _: NodeId) {
         if let Some(header) = fn_kind.header() {
             // Stability of const fn methods are covered in
             // `visit_trait_item` and `visit_impl_item` below; this is
@@ -827,6 +814,7 @@ macro_rules! gate_all {
     gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");
     gate_all!(const_generics, "const generics are unstable");
     gate_all!(decl_macro, "`macro` is experimental");
+    gate_all!(box_patterns, "box pattern syntax is experimental");
 
     visit::walk_crate(&mut visitor, krate);
 }
index af795e51792ff26f4ffc6fd41ee837c3e2210d94..5374671d4b895f10c843a38d27f26a8372415af0 100644 (file)
@@ -324,7 +324,9 @@ fn parse_pat_with_range_pat(
                 self.parse_pat_ident(BindingMode::ByRef(mutbl))?
             } else if self.eat_keyword(kw::Box) {
                 // Parse `box pat`
-                PatKind::Box(self.parse_pat_with_range_pat(false, None)?)
+                let pat = self.parse_pat_with_range_pat(false, None)?;
+                self.sess.gated_spans.box_patterns.borrow_mut().push(lo.to(self.prev_span));
+                PatKind::Box(pat)
             } else if self.can_be_ident_pat() {
                 // Parse `ident @ pat`
                 // This can give false positives and parse nullary enums,
index 30aeff752ec40b82db6cf9abff70619a194a8d4f..c8e60be1db948fb484e6e79524d37f42dbf29742 100644 (file)
@@ -40,6 +40,8 @@
     pub const_generics: Lock<Vec<Span>>,
     /// Spans collected for gating `decl_macro`, e.g. `macro m() {}`.
     pub decl_macro: Lock<Vec<Span>>,
+    /// Spans collected for gating `box_patterns`, e.g. `box 0`.
+    pub box_patterns: Lock<Vec<Span>>,
 }
 
 /// Info about a parsing session.
index 8bec16a974e800930de77eeffc8010469254a8c5..c5b926d5af28c86c1cc1ade736b83cb358034075 100644 (file)
@@ -2,3 +2,6 @@ fn main() {
     let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental
     println!("x: {}", x);
 }
+
+macro_rules! accept_pat { ($p:pat) => {} }
+accept_pat!(box 0); //~ ERROR box pattern syntax is experimental
index d2dafe93a862fbc0d2291ea747cdf6d8a9718637..1e47bd41e88705a7cc0f8330877fa5ddcc531cd5 100644 (file)
@@ -7,6 +7,15 @@ LL |     let box x = Box::new('c');
    = note: for more information, see https://github.com/rust-lang/rust/issues/29641
    = help: add `#![feature(box_patterns)]` to the crate attributes to enable
 
-error: aborting due to previous error
+error[E0658]: box pattern syntax is experimental
+  --> $DIR/feature-gate-box_patterns.rs:7:13
+   |
+LL | accept_pat!(box 0);
+   |             ^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/29641
+   = help: add `#![feature(box_patterns)]` to the crate attributes to enable
+
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0658`.
index 5fe72caf9c1ff7a9c3ee401a76dd4f6ab8e86761..9667711242ce61d57d9594051811c1bde10c98fd 100644 (file)
@@ -4,6 +4,7 @@
 // check-pass
 
 #![feature(or_patterns)]
+#![feature(box_patterns)]
 
 fn main() {}
 
index 9656a0b5de9ce1afa46a4590e271f6e51ec3c5c5..45b31f6125374254c69dcecb8879fc1c4bebe8f5 100644 (file)
@@ -3,6 +3,8 @@
 
 // check-pass
 
+#![feature(box_patterns)]
+
 fn main() {}
 
 macro_rules! accept_pat {