]> git.lizzy.rs Git - rust.git/commitdiff
dotdoteq_in_patterns feature gate
authorBadel2 <2badel2@gmail.com>
Thu, 21 Sep 2017 10:14:14 +0000 (12:14 +0200)
committerBadel2 <2badel2@gmail.com>
Fri, 22 Sep 2017 20:05:46 +0000 (22:05 +0200)
src/libsyntax/feature_gate.rs
src/test/compile-fail/feature-gate-dotdoteq_in_patterns.rs [new file with mode: 0644]
src/test/run-pass/inc-range-pat.rs

index 2fc451d5d004aef5de84a6560cc17795fdf8aad5..aa5a41430274a74348ef6f8253fba6a8eb89fcc3 100644 (file)
@@ -26,7 +26,7 @@
 use self::AttributeGate::*;
 
 use abi::Abi;
-use ast::{self, NodeId, PatKind, RangeEnd};
+use ast::{self, NodeId, PatKind, RangeEnd, RangeSyntax};
 use attr;
 use codemap::Spanned;
 use syntax_pos::Span;
@@ -392,6 +392,9 @@ pub fn new() -> Features {
 
     // allow `'_` placeholder lifetimes
     (active, underscore_lifetimes, "1.22.0", Some(44524)),
+
+    // allow `..=` in patterns (RFC 1192)
+    (active, dotdoteq_in_patterns, "1.22.0", Some(28237)),
 );
 
 declare_features! (
@@ -1491,6 +1494,10 @@ fn visit_pat(&mut self, pattern: &'a ast::Pat) {
                 gate_feature_post!(&self, exclusive_range_pattern, pattern.span,
                                    "exclusive range pattern syntax is experimental");
             }
+            PatKind::Range(_, _, RangeEnd::Included(RangeSyntax::DotDotEq)) => {
+                gate_feature_post!(&self, dotdoteq_in_patterns, pattern.span,
+                                   "`..=` syntax in patterns is experimental");
+            }
             _ => {}
         }
         visit::walk_pat(self, pattern)
diff --git a/src/test/compile-fail/feature-gate-dotdoteq_in_patterns.rs b/src/test/compile-fail/feature-gate-dotdoteq_in_patterns.rs
new file mode 100644 (file)
index 0000000..1fb139b
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub fn main() {
+    match 22 {
+        0 ..= 3 => {} //~ ERROR `..=` syntax in patterns is experimental
+        _ => {}
+    }
+}
index 237b41b6128cf8a8405bd750bdcee71ee75b0b5b..5faf36eddaf064267e6edca8ebe447f20b365eb1 100644 (file)
@@ -9,6 +9,8 @@
 // except according to those terms.
 
 // Test old and new syntax for inclusive range patterns.
+#![feature(dotdoteq_in_patterns)]
+
 
 fn main() {
     assert!(match 42 { 0 ... 100 => true, _ => false });