about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-09-21 20:11:00 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-10-24 00:32:03 +0200
commit665a876e307933c6480a6c55a3e38e88937aff2c (patch)
tree2f80aef4667e991b5a05f5a78e039e3ddd86d270 /src
parent2aff6b36d7ed5c25700669a92b4a43200ee0fe6b (diff)
downloadrust-665a876e307933c6480a6c55a3e38e88937aff2c.tar.gz
rust-665a876e307933c6480a6c55a3e38e88937aff2c.zip
pre-expansion gate exclusive_range_pattern
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/feature_gate/check.rs8
-rw-r--r--src/libsyntax/parse/parser/pat.rs9
-rw-r--r--src/libsyntax/sess.rs2
-rw-r--r--src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.rs6
-rw-r--r--src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.stderr15
-rw-r--r--src/test/ui/parser/pat-tuple-4.rs1
-rw-r--r--src/test/ui/parser/pat-tuple-4.stderr16
-rw-r--r--src/test/ui/parser/pat-tuple-5.stderr4
8 files changed, 33 insertions, 28 deletions
diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs
index 7c4668122a4..0b4289b139f 100644
--- a/src/libsyntax/feature_gate/check.rs
+++ b/src/libsyntax/feature_gate/check.rs
@@ -3,9 +3,8 @@ use super::accepted::ACCEPTED_FEATURES;
 use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
 use super::builtin_attrs::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
 
-use crate::ast::{self, NodeId, PatKind, RangeEnd, VariantData};
+use crate::ast::{self, NodeId, PatKind, VariantData};
 use crate::attr::{self, check_builtin_attribute};
-use crate::source_map::Spanned;
 use crate::edition::{ALL_EDITIONS, Edition};
 use crate::visit::{self, FnKind, Visitor};
 use crate::parse::token;
@@ -529,10 +528,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
                     }
                 }
             }
-            PatKind::Range(_, _, Spanned { node: RangeEnd::Excluded, .. }) => {
-                gate_feature_post!(&self, exclusive_range_pattern, pattern.span,
-                                   "exclusive range pattern syntax is experimental");
-            }
             _ => {}
         }
         visit::walk_pat(self, pattern)
@@ -815,6 +810,7 @@ pub fn check_crate(krate: &ast::Crate,
     gate_all!(const_generics, "const generics are unstable");
     gate_all!(decl_macro, "`macro` is experimental");
     gate_all!(box_patterns, "box pattern syntax is experimental");
+    gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
 
     visit::walk_crate(&mut visitor, krate);
 }
diff --git a/src/libsyntax/parse/parser/pat.rs b/src/libsyntax/parse/parser/pat.rs
index 5374671d4b8..969d5dd8374 100644
--- a/src/libsyntax/parse/parser/pat.rs
+++ b/src/libsyntax/parse/parser/pat.rs
@@ -611,6 +611,11 @@ impl<'a> Parser<'a> {
         Ok(PatKind::Mac(mac))
     }
 
+    fn excluded_range_end(&self, span: Span) -> RangeEnd {
+        self.sess.gated_spans.exclusive_range_pattern.borrow_mut().push(span);
+        RangeEnd::Excluded
+    }
+
     /// Parse a range pattern `$path $form $end?` where `$form = ".." | "..." | "..=" ;`.
     /// The `$path` has already been parsed and the next token is the `$form`.
     fn parse_pat_range_starting_with_path(
@@ -620,7 +625,7 @@ impl<'a> Parser<'a> {
         path: Path
     ) -> PResult<'a, PatKind> {
         let (end_kind, form) = match self.token.kind {
-            token::DotDot => (RangeEnd::Excluded, ".."),
+            token::DotDot => (self.excluded_range_end(self.token.span), ".."),
             token::DotDotDot => (RangeEnd::Included(RangeSyntax::DotDotDot), "..."),
             token::DotDotEq => (RangeEnd::Included(RangeSyntax::DotDotEq), "..="),
             _ => panic!("can only parse `..`/`...`/`..=` for ranges (checked above)"),
@@ -643,7 +648,7 @@ impl<'a> Parser<'a> {
         } else if self.eat(&token::DotDotEq) {
             (RangeEnd::Included(RangeSyntax::DotDotEq), "..=")
         } else if self.eat(&token::DotDot) {
-            (RangeEnd::Excluded, "..")
+            (self.excluded_range_end(op_span), "..")
         } else {
             panic!("impossible case: we already matched on a range-operator token")
         };
diff --git a/src/libsyntax/sess.rs b/src/libsyntax/sess.rs
index c8e60be1db9..09331924c60 100644
--- a/src/libsyntax/sess.rs
+++ b/src/libsyntax/sess.rs
@@ -42,6 +42,8 @@ crate struct GatedSpans {
     pub decl_macro: Lock<Vec<Span>>,
     /// Spans collected for gating `box_patterns`, e.g. `box 0`.
     pub box_patterns: Lock<Vec<Span>>,
+    /// Spans collected for gating `exclusive_range_pattern`, e.g. `0..2`.
+    pub exclusive_range_pattern: Lock<Vec<Span>>,
 }
 
 /// Info about a parsing session.
diff --git a/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.rs b/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.rs
index ded08b93fe8..594ec73fe26 100644
--- a/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.rs
+++ b/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.rs
@@ -1,6 +1,10 @@
-pub fn main() {
+#[cfg(FALSE)]
+fn foo() {
     match 22 {
         0 .. 3 => {} //~ ERROR exclusive range pattern syntax is experimental
+        PATH .. 3 => {} //~ ERROR exclusive range pattern syntax is experimental
         _ => {}
     }
 }
+
+fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.stderr b/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.stderr
index ee20408d178..075fdbed90d 100644
--- a/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.stderr
+++ b/src/test/ui/feature-gates/feature-gate-exclusive-range-pattern.stderr
@@ -1,12 +1,21 @@
 error[E0658]: exclusive range pattern syntax is experimental
-  --> $DIR/feature-gate-exclusive-range-pattern.rs:3:9
+  --> $DIR/feature-gate-exclusive-range-pattern.rs:4:11
    |
 LL |         0 .. 3 => {}
-   |         ^^^^^^
+   |           ^^
    |
    = note: for more information, see https://github.com/rust-lang/rust/issues/37854
    = help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable
 
-error: aborting due to previous error
+error[E0658]: exclusive range pattern syntax is experimental
+  --> $DIR/feature-gate-exclusive-range-pattern.rs:5:14
+   |
+LL |         PATH .. 3 => {}
+   |              ^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/37854
+   = help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable
+
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/parser/pat-tuple-4.rs b/src/test/ui/parser/pat-tuple-4.rs
index 2f03160430a..6b8c146949a 100644
--- a/src/test/ui/parser/pat-tuple-4.rs
+++ b/src/test/ui/parser/pat-tuple-4.rs
@@ -4,7 +4,6 @@ fn main() {
     match 0 {
         (.. PAT) => {}
         //~^ ERROR `..X` range patterns are not supported
-        //~| ERROR exclusive range pattern syntax is experimental
     }
 }
 
diff --git a/src/test/ui/parser/pat-tuple-4.stderr b/src/test/ui/parser/pat-tuple-4.stderr
index af3ecce1846..1962dc4ff20 100644
--- a/src/test/ui/parser/pat-tuple-4.stderr
+++ b/src/test/ui/parser/pat-tuple-4.stderr
@@ -4,17 +4,8 @@ error: `..X` range patterns are not supported
 LL |         (.. PAT) => {}
    |          ^^^^^^ help: try using the minimum value for the type: `MIN..PAT`
 
-error[E0658]: exclusive range pattern syntax is experimental
-  --> $DIR/pat-tuple-4.rs:5:10
-   |
-LL |         (.. PAT) => {}
-   |          ^^^^^^
-   |
-   = note: for more information, see https://github.com/rust-lang/rust/issues/37854
-   = help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable
-
 error[E0308]: mismatched types
-  --> $DIR/pat-tuple-4.rs:11:30
+  --> $DIR/pat-tuple-4.rs:10:30
    |
 LL | const RECOVERY_WITNESS: () = 0;
    |                              ^ expected (), found integer
@@ -22,7 +13,6 @@ LL | const RECOVERY_WITNESS: () = 0;
    = note: expected type `()`
               found type `{integer}`
 
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
 
-Some errors have detailed explanations: E0308, E0658.
-For more information about an error, try `rustc --explain E0308`.
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/parser/pat-tuple-5.stderr b/src/test/ui/parser/pat-tuple-5.stderr
index 09ebdc29a21..17155b4dd49 100644
--- a/src/test/ui/parser/pat-tuple-5.stderr
+++ b/src/test/ui/parser/pat-tuple-5.stderr
@@ -5,10 +5,10 @@ LL |         (PAT ..) => {}
    |          ^^^^^^ help: try using the maximum value for the type: `PAT..MAX`
 
 error[E0658]: exclusive range pattern syntax is experimental
-  --> $DIR/pat-tuple-5.rs:5:10
+  --> $DIR/pat-tuple-5.rs:5:14
    |
 LL |         (PAT ..) => {}
-   |          ^^^^^^
+   |              ^^
    |
    = note: for more information, see https://github.com/rust-lang/rust/issues/37854
    = help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable