From: Badel2 <2badel2@gmail.com> Date: Thu, 21 Sep 2017 10:14:14 +0000 (+0200) Subject: dotdoteq_in_patterns feature gate X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=54c4a830843d8de97d1dd3f936f9e3415bc96ef9;p=rust.git dotdoteq_in_patterns feature gate --- diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 2fc451d5d00..aa5a4143027 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -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 index 00000000000..1fb139bf07f --- /dev/null +++ b/src/test/compile-fail/feature-gate-dotdoteq_in_patterns.rs @@ -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 or the MIT license +// , 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 + _ => {} + } +} diff --git a/src/test/run-pass/inc-range-pat.rs b/src/test/run-pass/inc-range-pat.rs index 237b41b6128..5faf36eddaf 100644 --- a/src/test/run-pass/inc-range-pat.rs +++ b/src/test/run-pass/inc-range-pat.rs @@ -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 });