From 057715557b51af125847da6d19b2e016283c5ae7 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Mon, 28 May 2018 19:42:11 -0700 Subject: [PATCH 1/3] migrate codebase to `..=` inclusive range patterns These were stabilized in March 2018's #47813, and are the Preferred Way to Do It going forward (q.v. #51043). --- src/libcore/ascii.rs | 4 +- src/libcore/char/decode.rs | 18 +++---- src/libcore/char/methods.rs | 18 +++---- src/libcore/fmt/num.rs | 14 ++--- src/libcore/slice/mod.rs | 6 +-- src/libcore/str/lossy.rs | 14 ++--- src/libcore/str/mod.rs | 14 ++--- src/libcore/tests/slice.rs | 4 +- src/librustc_apfloat/ieee.rs | 4 +- src/librustc_codegen_utils/symbol_names.rs | 2 +- src/librustc_mir/diagnostics.rs | 4 +- src/librustc_mir/hair/pattern/check_match.rs | 2 +- src/librustc_target/abi/call/mod.rs | 10 ++-- src/librustc_target/abi/mod.rs | 16 +++--- src/librustc_typeck/diagnostics.rs | 6 +-- src/libserialize/hex.rs | 6 +-- src/libserialize/json.rs | 22 ++++---- src/libstd/sys_common/backtrace.rs | 2 +- src/libstd/sys_common/wtf8.rs | 12 ++--- src/libsyntax/ast.rs | 4 +- src/libsyntax/parse/lexer/mod.rs | 4 +- src/libsyntax_ext/format_foreign.rs | 14 ++--- src/libsyntax_pos/lib.rs | 4 +- src/libterm/terminfo/parm.rs | 10 ++-- src/test/compile-fail/associated-path-shl.rs | 2 +- src/test/compile-fail/issue-27895.rs | 2 +- src/test/compile-fail/issue-41255.rs | 2 +- src/test/compile-fail/match-range-fail-2.rs | 4 +- src/test/compile-fail/match-range-fail.rs | 6 +-- .../non-constant-in-const-path.rs | 2 +- .../compile-fail/patkind-litrange-no-expr.rs | 3 +- .../compile-fail/qualified-path-params.rs | 2 +- .../compile-fail/refutable-pattern-errors.rs | 4 +- .../run-pass-fulldeps/ast_stmt_expr_attr.rs | 8 +-- src/test/run-pass/byte-literals.rs | 2 +- .../inferred-suffix-in-pattern-range.rs | 6 +-- src/test/run-pass/issue-12582.rs | 4 +- src/test/run-pass/issue-13027.rs | 52 +++++++++---------- src/test/run-pass/issue-13867.rs | 14 ++--- src/test/run-pass/issue-18060.rs | 6 +-- src/test/run-pass/issue-18464.rs | 2 +- src/test/run-pass/issue-21475.rs | 6 +-- src/test/run-pass/issue-26251.rs | 4 +- src/test/run-pass/issue-35423.rs | 2 +- src/test/run-pass/issue-7222.rs | 2 +- src/test/run-pass/macro-literal.rs | 20 +++---- src/test/run-pass/match-range-infer.rs | 6 +-- src/test/run-pass/match-range-static.rs | 2 +- src/test/run-pass/match-range.rs | 14 ++--- .../rfc-2005-default-binding-mode/range.rs | 4 +- src/test/ui/check_match/issue-43253.rs | 8 +-- src/test/ui/check_match/issue-43253.stderr | 4 +- src/test/ui/const-eval/const_signed_pat.rs | 2 +- src/test/ui/const-eval/ref_to_int_match.rs | 4 +- .../ui/const-eval/ref_to_int_match.stderr | 2 +- src/test/ui/error-codes/E0029-teach.rs | 2 +- src/test/ui/error-codes/E0029-teach.stderr | 2 +- src/test/ui/error-codes/E0029.rs | 2 +- src/test/ui/error-codes/E0029.stderr | 2 +- src/test/ui/error-codes/E0030-teach.rs | 2 +- src/test/ui/error-codes/E0030-teach.stderr | 2 +- src/test/ui/error-codes/E0030.rs | 2 +- src/test/ui/error-codes/E0030.stderr | 2 +- src/test/ui/error-codes/E0308-4.rs | 2 +- src/test/ui/error-codes/E0308-4.stderr | 2 +- 65 files changed, 217 insertions(+), 218 deletions(-) diff --git a/src/libcore/ascii.rs b/src/libcore/ascii.rs index e6b0569281f89..6ee91e0b22ff0 100644 --- a/src/libcore/ascii.rs +++ b/src/libcore/ascii.rs @@ -108,7 +108,7 @@ pub fn escape_default(c: u8) -> EscapeDefault { b'\\' => ([b'\\', b'\\', 0, 0], 2), b'\'' => ([b'\\', b'\'', 0, 0], 2), b'"' => ([b'\\', b'"', 0, 0], 2), - b'\x20' ... b'\x7e' => ([c, 0, 0, 0], 1), + b'\x20' ..= b'\x7e' => ([c, 0, 0, 0], 1), _ => ([b'\\', b'x', hexify(c >> 4), hexify(c & 0xf)], 4), }; @@ -116,7 +116,7 @@ pub fn escape_default(c: u8) -> EscapeDefault { fn hexify(b: u8) -> u8 { match b { - 0 ... 9 => b'0' + b, + 0 ..= 9 => b'0' + b, _ => b'a' + b - 10, } } diff --git a/src/libcore/char/decode.rs b/src/libcore/char/decode.rs index 45a73191db2f2..0b8dce19dffa1 100644 --- a/src/libcore/char/decode.rs +++ b/src/libcore/char/decode.rs @@ -64,7 +64,7 @@ impl> Iterator for DecodeUtf8 { } } macro_rules! continuation_byte { - () => { continuation_byte!(0x80...0xBF) }; + () => { continuation_byte!(0x80..=0xBF) }; ($range: pat) => { match self.0.peek() { Some(&byte @ $range) => { @@ -77,35 +77,35 @@ impl> Iterator for DecodeUtf8 { } match first_byte { - 0x00...0x7F => { + 0x00..=0x7F => { first_byte!(0b1111_1111); } - 0xC2...0xDF => { + 0xC2..=0xDF => { first_byte!(0b0001_1111); continuation_byte!(); } 0xE0 => { first_byte!(0b0000_1111); - continuation_byte!(0xA0...0xBF); // 0x80...0x9F here are overlong + continuation_byte!(0xA0..=0xBF); // 0x80..=0x9F here are overlong continuation_byte!(); } - 0xE1...0xEC | 0xEE...0xEF => { + 0xE1..=0xEC | 0xEE..=0xEF => { first_byte!(0b0000_1111); continuation_byte!(); continuation_byte!(); } 0xED => { first_byte!(0b0000_1111); - continuation_byte!(0x80...0x9F); // 0xA0..0xBF here are surrogates + continuation_byte!(0x80..=0x9F); // 0xA0..0xBF here are surrogates continuation_byte!(); } 0xF0 => { first_byte!(0b0000_0111); - continuation_byte!(0x90...0xBF); // 0x80..0x8F here are overlong + continuation_byte!(0x90..=0xBF); // 0x80..0x8F here are overlong continuation_byte!(); continuation_byte!(); } - 0xF1...0xF3 => { + 0xF1..=0xF3 => { first_byte!(0b0000_0111); continuation_byte!(); continuation_byte!(); @@ -113,7 +113,7 @@ impl> Iterator for DecodeUtf8 { } 0xF4 => { first_byte!(0b0000_0111); - continuation_byte!(0x80...0x8F); // 0x90..0xBF here are beyond char::MAX + continuation_byte!(0x80..=0x8F); // 0x90..0xBF here are beyond char::MAX continuation_byte!(); continuation_byte!(); } diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index f6b201fe06dea..eee78de903628 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -125,9 +125,9 @@ impl char { panic!("to_digit: radix is too high (maximum 36)"); } let val = match self { - '0' ... '9' => self as u32 - '0' as u32, - 'a' ... 'z' => self as u32 - 'a' as u32 + 10, - 'A' ... 'Z' => self as u32 - 'A' as u32 + 10, + '0' ..= '9' => self as u32 - '0' as u32, + 'a' ..= 'z' => self as u32 - 'a' as u32 + 10, + 'A' ..= 'Z' => self as u32 - 'A' as u32 + 10, _ => return None, }; if val < radix { Some(val) } @@ -305,7 +305,7 @@ impl char { '\r' => EscapeDefaultState::Backslash('r'), '\n' => EscapeDefaultState::Backslash('n'), '\\' | '\'' | '"' => EscapeDefaultState::Backslash(self), - '\x20' ... '\x7e' => EscapeDefaultState::Char(self), + '\x20' ..= '\x7e' => EscapeDefaultState::Char(self), _ => EscapeDefaultState::Unicode(self.escape_unicode()) }; EscapeDefault { state: init_state } @@ -543,7 +543,7 @@ impl char { #[inline] pub fn is_alphabetic(self) -> bool { match self { - 'a'...'z' | 'A'...'Z' => true, + 'a'..='z' | 'A'..='Z' => true, c if c > '\x7f' => derived_property::Alphabetic(c), _ => false, } @@ -599,7 +599,7 @@ impl char { #[inline] pub fn is_lowercase(self) -> bool { match self { - 'a'...'z' => true, + 'a'..='z' => true, c if c > '\x7f' => derived_property::Lowercase(c), _ => false, } @@ -627,7 +627,7 @@ impl char { #[inline] pub fn is_uppercase(self) -> bool { match self { - 'A'...'Z' => true, + 'A'..='Z' => true, c if c > '\x7f' => derived_property::Uppercase(c), _ => false, } @@ -654,7 +654,7 @@ impl char { #[inline] pub fn is_whitespace(self) -> bool { match self { - ' ' | '\x09'...'\x0d' => true, + ' ' | '\x09'..='\x0d' => true, c if c > '\x7f' => property::White_Space(c), _ => false, } @@ -737,7 +737,7 @@ impl char { #[inline] pub fn is_numeric(self) -> bool { match self { - '0'...'9' => true, + '0'..='9' => true, c if c > '\x7f' => general_category::N(c), _ => false, } diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index 4451ab445cc5c..51391fa50d56f 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -121,19 +121,19 @@ macro_rules! radix { fn digit(x: u8) -> u8 { match x { $($x => $conv,)+ - x => panic!("number not in the range 0..{}: {}", Self::BASE - 1, x), + x => panic!("number not in the range 0..={}: {}", Self::BASE - 1, x), } } } } } -radix! { Binary, 2, "0b", x @ 0 ... 1 => b'0' + x } -radix! { Octal, 8, "0o", x @ 0 ... 7 => b'0' + x } -radix! { LowerHex, 16, "0x", x @ 0 ... 9 => b'0' + x, - x @ 10 ... 15 => b'a' + (x - 10) } -radix! { UpperHex, 16, "0x", x @ 0 ... 9 => b'0' + x, - x @ 10 ... 15 => b'A' + (x - 10) } +radix! { Binary, 2, "0b", x @ 0 ..= 1 => b'0' + x } +radix! { Octal, 8, "0o", x @ 0 ..= 7 => b'0' + x } +radix! { LowerHex, 16, "0x", x @ 0 ..= 9 => b'0' + x, + x @ 10 ..= 15 => b'a' + (x - 10) } +radix! { UpperHex, 16, "0x", x @ 0 ..= 9 => b'0' + x, + x @ 10 ..= 15 => b'A' + (x - 10) } macro_rules! int_base { ($Trait:ident for $T:ident as $U:ident -> $Radix:ident) => { diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 6f4c130d8f318..e74e527927d7b 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1230,7 +1230,7 @@ impl [T] { /// assert_eq!(s.binary_search(&4), Err(7)); /// assert_eq!(s.binary_search(&100), Err(13)); /// let r = s.binary_search(&1); - /// assert!(match r { Ok(1...4) => true, _ => false, }); + /// assert!(match r { Ok(1..=4) => true, _ => false, }); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn binary_search(&self, x: &T) -> Result @@ -1268,7 +1268,7 @@ impl [T] { /// assert_eq!(s.binary_search_by(|probe| probe.cmp(&seek)), Err(13)); /// let seek = 1; /// let r = s.binary_search_by(|probe| probe.cmp(&seek)); - /// assert!(match r { Ok(1...4) => true, _ => false, }); + /// assert!(match r { Ok(1..=4) => true, _ => false, }); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -1325,7 +1325,7 @@ impl [T] { /// assert_eq!(s.binary_search_by_key(&4, |&(a,b)| b), Err(7)); /// assert_eq!(s.binary_search_by_key(&100, |&(a,b)| b), Err(13)); /// let r = s.binary_search_by_key(&1, |&(a,b)| b); - /// assert!(match r { Ok(1...4) => true, _ => false, }); + /// assert!(match r { Ok(1..=4) => true, _ => false, }); /// ``` #[stable(feature = "slice_binary_search_by_key", since = "1.10.0")] #[inline] diff --git a/src/libcore/str/lossy.rs b/src/libcore/str/lossy.rs index 30b7267da7c5e..5cfb36d3b195b 100644 --- a/src/libcore/str/lossy.rs +++ b/src/libcore/str/lossy.rs @@ -101,10 +101,10 @@ impl<'a> Iterator for Utf8LossyChunksIter<'a> { } 3 => { match (byte, safe_get(self.source, i)) { - (0xE0, 0xA0 ... 0xBF) => (), - (0xE1 ... 0xEC, 0x80 ... 0xBF) => (), - (0xED, 0x80 ... 0x9F) => (), - (0xEE ... 0xEF, 0x80 ... 0xBF) => (), + (0xE0, 0xA0 ..= 0xBF) => (), + (0xE1 ..= 0xEC, 0x80 ..= 0xBF) => (), + (0xED, 0x80 ..= 0x9F) => (), + (0xEE ..= 0xEF, 0x80 ..= 0xBF) => (), _ => { error!(); } @@ -117,9 +117,9 @@ impl<'a> Iterator for Utf8LossyChunksIter<'a> { } 4 => { match (byte, safe_get(self.source, i)) { - (0xF0, 0x90 ... 0xBF) => (), - (0xF1 ... 0xF3, 0x80 ... 0xBF) => (), - (0xF4, 0x80 ... 0x8F) => (), + (0xF0, 0x90 ..= 0xBF) => (), + (0xF1 ..= 0xF3, 0x80 ..= 0xBF) => (), + (0xF4, 0x80 ..= 0x8F) => (), _ => { error!(); } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 5e1a9c25a2190..42fb1bc238b8e 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1484,10 +1484,10 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> { }, 3 => { match (first, next!()) { - (0xE0 , 0xA0 ... 0xBF) | - (0xE1 ... 0xEC, 0x80 ... 0xBF) | - (0xED , 0x80 ... 0x9F) | - (0xEE ... 0xEF, 0x80 ... 0xBF) => {} + (0xE0 , 0xA0 ..= 0xBF) | + (0xE1 ..= 0xEC, 0x80 ..= 0xBF) | + (0xED , 0x80 ..= 0x9F) | + (0xEE ..= 0xEF, 0x80 ..= 0xBF) => {} _ => err!(Some(1)) } if next!() & !CONT_MASK != TAG_CONT_U8 { @@ -1496,9 +1496,9 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> { } 4 => { match (first, next!()) { - (0xF0 , 0x90 ... 0xBF) | - (0xF1 ... 0xF3, 0x80 ... 0xBF) | - (0xF4 , 0x80 ... 0x8F) => {} + (0xF0 , 0x90 ..= 0xBF) | + (0xF1 ..= 0xF3, 0x80 ..= 0xBF) | + (0xF4 , 0x80 ..= 0x8F) => {} _ => err!(Some(1)) } if next!() & !CONT_MASK != TAG_CONT_U8 { diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index fcd79222e1699..7981567067dad 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -60,8 +60,8 @@ fn test_binary_search() { assert_eq!(b.binary_search(&0), Err(0)); assert_eq!(b.binary_search(&1), Ok(0)); assert_eq!(b.binary_search(&2), Err(1)); - assert!(match b.binary_search(&3) { Ok(1...3) => true, _ => false }); - assert!(match b.binary_search(&3) { Ok(1...3) => true, _ => false }); + assert!(match b.binary_search(&3) { Ok(1..=3) => true, _ => false }); + assert!(match b.binary_search(&3) { Ok(1..=3) => true, _ => false }); assert_eq!(b.binary_search(&4), Err(4)); assert_eq!(b.binary_search(&5), Err(4)); assert_eq!(b.binary_search(&6), Err(4)); diff --git a/src/librustc_apfloat/ieee.rs b/src/librustc_apfloat/ieee.rs index 7abd02b6656f3..b21448df582a9 100644 --- a/src/librustc_apfloat/ieee.rs +++ b/src/librustc_apfloat/ieee.rs @@ -1753,9 +1753,9 @@ impl IeeeFloat { } else { loss = Some(match hex_value { 0 => Loss::ExactlyZero, - 1...7 => Loss::LessThanHalf, + 1..=7 => Loss::LessThanHalf, 8 => Loss::ExactlyHalf, - 9...15 => Loss::MoreThanHalf, + 9..=15 => Loss::MoreThanHalf, _ => unreachable!(), }); } diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index dcb82e5c424e5..ac71ecff96457 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -424,7 +424,7 @@ pub fn sanitize(result: &mut String, s: &str) -> bool { '-' | ':' => result.push('.'), // These are legal symbols - 'a'...'z' | 'A'...'Z' | '0'...'9' | '_' | '.' | '$' => result.push(c), + 'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '.' | '$' => result.push(c), _ => { result.push('$'); diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs index f195775bf86e9..c2da1bee3954a 100644 --- a/src/librustc_mir/diagnostics.rs +++ b/src/librustc_mir/diagnostics.rs @@ -306,9 +306,9 @@ For example: ```compile_fail match 5u32 { // This range is ok, albeit pointless. - 1 ... 1 => {} + 1 ..= 1 => {} // This range is empty, and the compiler can tell. - 1000 ... 5 => {} + 1000 ..= 5 => {} } ``` "##, diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 4ac896d84ff6e..24301e970f506 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -481,7 +481,7 @@ fn check_exhaustive<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, let joined_patterns = match witnesses.len() { 0 => bug!(), 1 => format!("`{}`", witnesses[0]), - 2...LIMIT => { + 2..=LIMIT => { let (tail, head) = witnesses.split_last().unwrap(); let head: Vec<_> = head.iter().map(|w| w.to_string()).collect(); format!("`{}` and `{}`", head.join("`, `"), tail) diff --git a/src/librustc_target/abi/call/mod.rs b/src/librustc_target/abi/call/mod.rs index fcae9ea22bba1..3195823eb0982 100644 --- a/src/librustc_target/abi/call/mod.rs +++ b/src/librustc_target/abi/call/mod.rs @@ -139,11 +139,11 @@ impl Reg { RegKind::Integer => { match self.size.bits() { 1 => dl.i1_align, - 2...8 => dl.i8_align, - 9...16 => dl.i16_align, - 17...32 => dl.i32_align, - 33...64 => dl.i64_align, - 65...128 => dl.i128_align, + 2..=8 => dl.i8_align, + 9..=16 => dl.i16_align, + 17..=32 => dl.i32_align, + 33..=64 => dl.i64_align, + 65..=128 => dl.i128_align, _ => panic!("unsupported integer: {:?}", self) } } diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index 7ff04df623399..9003e30357cbd 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -441,10 +441,10 @@ impl Integer { /// Find the smallest Integer type which can represent the signed value. pub fn fit_signed(x: i128) -> Integer { match x { - -0x0000_0000_0000_0080...0x0000_0000_0000_007f => I8, - -0x0000_0000_0000_8000...0x0000_0000_0000_7fff => I16, - -0x0000_0000_8000_0000...0x0000_0000_7fff_ffff => I32, - -0x8000_0000_0000_0000...0x7fff_ffff_ffff_ffff => I64, + -0x0000_0000_0000_0080..=0x0000_0000_0000_007f => I8, + -0x0000_0000_0000_8000..=0x0000_0000_0000_7fff => I16, + -0x0000_0000_8000_0000..=0x0000_0000_7fff_ffff => I32, + -0x8000_0000_0000_0000..=0x7fff_ffff_ffff_ffff => I64, _ => I128 } } @@ -452,10 +452,10 @@ impl Integer { /// Find the smallest Integer type which can represent the unsigned value. pub fn fit_unsigned(x: u128) -> Integer { match x { - 0...0x0000_0000_0000_00ff => I8, - 0...0x0000_0000_0000_ffff => I16, - 0...0x0000_0000_ffff_ffff => I32, - 0...0xffff_ffff_ffff_ffff => I64, + 0..=0x0000_0000_0000_00ff => I8, + 0..=0x0000_0000_0000_ffff => I16, + 0..=0x0000_0000_ffff_ffff => I32, + 0..=0xffff_ffff_ffff_ffff => I64, _ => I128, } } diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index b0b72256edccf..dd09bf96da594 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -207,7 +207,7 @@ let string = "salutations !"; // The ordering relation for strings can't be evaluated at compile time, // so this doesn't work: match string { - "hello" ... "world" => {} + "hello" ..= "world" => {} _ => {} } @@ -2146,7 +2146,7 @@ fn main() -> i32 { 0 } let x = 1u8; match x { - 0u8...3i8 => (), + 0u8..=3i8 => (), // error: mismatched types in range: expected u8, found i8 _ => () } @@ -2189,7 +2189,7 @@ as the type you're matching on. Example: let x = 1u8; match x { - 0u8...3u8 => (), // ok! + 0u8..=3u8 => (), // ok! _ => () } ``` diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index b5b344e8d5f24..4c306d9b2d375 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -125,9 +125,9 @@ impl FromHex for str { buf <<= 4; match byte { - b'A'...b'F' => buf |= byte - b'A' + 10, - b'a'...b'f' => buf |= byte - b'a' + 10, - b'0'...b'9' => buf |= byte - b'0', + b'A'..=b'F' => buf |= byte - b'A' + 10, + b'a'..=b'f' => buf |= byte - b'a' + 10, + b'0'..=b'9' => buf |= byte - b'0', b' '|b'\r'|b'\n'|b'\t' => { buf >>= 4; continue diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index efdad7d801ab5..9959d5ce40d2d 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -1557,14 +1557,14 @@ impl> Parser { self.bump(); // A leading '0' must be the only digit before the decimal point. - if let '0' ... '9' = self.ch_or_null() { + if let '0' ..= '9' = self.ch_or_null() { return self.error(InvalidNumber) } }, - '1' ... '9' => { + '1' ..= '9' => { while !self.eof() { match self.ch_or_null() { - c @ '0' ... '9' => { + c @ '0' ..= '9' => { accum = accum.wrapping_mul(10); accum = accum.wrapping_add((c as u64) - ('0' as u64)); @@ -1588,14 +1588,14 @@ impl> Parser { // Make sure a digit follows the decimal place. match self.ch_or_null() { - '0' ... '9' => (), + '0' ..= '9' => (), _ => return self.error(InvalidNumber) } let mut dec = 1.0; while !self.eof() { match self.ch_or_null() { - c @ '0' ... '9' => { + c @ '0' ..= '9' => { dec /= 10.0; res += (((c as isize) - ('0' as isize)) as f64) * dec; self.bump(); @@ -1622,12 +1622,12 @@ impl> Parser { // Make sure a digit follows the exponent place. match self.ch_or_null() { - '0' ... '9' => (), + '0' ..= '9' => (), _ => return self.error(InvalidNumber) } while !self.eof() { match self.ch_or_null() { - c @ '0' ... '9' => { + c @ '0' ..= '9' => { exp *= 10; exp += (c as usize) - ('0' as usize); @@ -1653,7 +1653,7 @@ impl> Parser { while i < 4 && !self.eof() { self.bump(); n = match self.ch_or_null() { - c @ '0' ... '9' => n * 16 + ((c as u16) - ('0' as u16)), + c @ '0' ..= '9' => n * 16 + ((c as u16) - ('0' as u16)), 'a' | 'A' => n * 16 + 10, 'b' | 'B' => n * 16 + 11, 'c' | 'C' => n * 16 + 12, @@ -1695,13 +1695,13 @@ impl> Parser { 'r' => res.push('\r'), 't' => res.push('\t'), 'u' => match self.decode_hex_escape()? { - 0xDC00 ... 0xDFFF => { + 0xDC00 ..= 0xDFFF => { return self.error(LoneLeadingSurrogateInHexEscape) } // Non-BMP characters are encoded as a sequence of // two hex escapes, representing UTF-16 surrogates. - n1 @ 0xD800 ... 0xDBFF => { + n1 @ 0xD800 ..= 0xDBFF => { match (self.next_char(), self.next_char()) { (Some('\\'), Some('u')) => (), _ => return self.error(UnexpectedEndOfHexEscape), @@ -1928,7 +1928,7 @@ impl> Parser { 'n' => { self.parse_ident("ull", NullValue) } 't' => { self.parse_ident("rue", BooleanValue(true)) } 'f' => { self.parse_ident("alse", BooleanValue(false)) } - '0' ... '9' | '-' => self.parse_number(), + '0' ..= '9' | '-' => self.parse_number(), '"' => match self.parse_str() { Ok(s) => StringValue(s), Err(e) => Error(e), diff --git a/src/libstd/sys_common/backtrace.rs b/src/libstd/sys_common/backtrace.rs index 20109d2d0d5ac..61d7ed463dd38 100644 --- a/src/libstd/sys_common/backtrace.rs +++ b/src/libstd/sys_common/backtrace.rs @@ -263,7 +263,7 @@ pub fn demangle(writer: &mut Write, mut s: &str, format: PrintFormat) -> io::Res let candidate = &s[i + llvm.len()..]; let all_hex = candidate.chars().all(|c| { match c { - 'A' ... 'F' | '0' ... '9' => true, + 'A' ..= 'F' | '0' ..= '9' => true, _ => false, } }); diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs index 14a2555adf9ba..bbb5980bd9da6 100644 --- a/src/libstd/sys_common/wtf8.rs +++ b/src/libstd/sys_common/wtf8.rs @@ -76,7 +76,7 @@ impl CodePoint { #[inline] pub fn from_u32(value: u32) -> Option { match value { - 0 ... 0x10FFFF => Some(CodePoint { value: value }), + 0 ..= 0x10FFFF => Some(CodePoint { value: value }), _ => None } } @@ -101,7 +101,7 @@ impl CodePoint { #[inline] pub fn to_char(&self) -> Option { match self.value { - 0xD800 ... 0xDFFF => None, + 0xD800 ..= 0xDFFF => None, _ => Some(unsafe { char::from_u32_unchecked(self.value) }) } } @@ -305,7 +305,7 @@ impl Wtf8Buf { /// like concatenating ill-formed UTF-16 strings effectively would. #[inline] pub fn push(&mut self, code_point: CodePoint) { - if let trail @ 0xDC00...0xDFFF = code_point.to_u32() { + if let trail @ 0xDC00..=0xDFFF = code_point.to_u32() { if let Some(lead) = (&*self).final_lead_surrogate() { let len_without_lead_surrogate = self.len() - 3; self.bytes.truncate(len_without_lead_surrogate); @@ -525,7 +525,7 @@ impl Wtf8 { #[inline] pub fn ascii_byte_at(&self, position: usize) -> u8 { match self.bytes[position] { - ascii_byte @ 0x00 ... 0x7F => ascii_byte, + ascii_byte @ 0x00 ..= 0x7F => ascii_byte, _ => 0xFF } } @@ -630,7 +630,7 @@ impl Wtf8 { return None } match &self.bytes[(len - 3)..] { - &[0xED, b2 @ 0xA0...0xAF, b3] => Some(decode_surrogate(b2, b3)), + &[0xED, b2 @ 0xA0..=0xAF, b3] => Some(decode_surrogate(b2, b3)), _ => None } } @@ -642,7 +642,7 @@ impl Wtf8 { return None } match &self.bytes[..3] { - &[0xED, b2 @ 0xB0...0xBF, b3] => Some(decode_surrogate(b2, b3)), + &[0xED, b2 @ 0xB0..=0xBF, b3] => Some(decode_surrogate(b2, b3)), _ => None } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a57a9b95e5f77..a09055e6c4aa5 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -843,11 +843,11 @@ pub struct Local { /// An arm of a 'match'. /// -/// E.g. `0...10 => { println!("match!") }` as in +/// E.g. `0..=10 => { println!("match!") }` as in /// /// ``` /// match 123 { -/// 0...10 => { println!("match!") }, +/// 0..=10 => { println!("match!") }, /// _ => { println!("no match!") }, /// } /// ``` diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 5353ff9a1e13d..c09cfd910d207 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -266,7 +266,7 @@ impl<'a> StringReader<'a> { /// Pushes a character to a message string for error reporting fn push_escaped_char_for_msg(m: &mut String, c: char) { match c { - '\u{20}'...'\u{7e}' => { + '\u{20}'..='\u{7e}' => { // Don't escape \, ' or " for user-facing messages m.push(c); } @@ -779,7 +779,7 @@ impl<'a> StringReader<'a> { base = 16; num_digits = self.scan_digits(16, 16); } - '0'...'9' | '_' | '.' | 'e' | 'E' => { + '0'..='9' | '_' | '.' | 'e' | 'E' => { num_digits = self.scan_digits(10, 10) + 1; } _ => { diff --git a/src/libsyntax_ext/format_foreign.rs b/src/libsyntax_ext/format_foreign.rs index 0dd8f0c55d8d4..2393af76c340b 100644 --- a/src/libsyntax_ext/format_foreign.rs +++ b/src/libsyntax_ext/format_foreign.rs @@ -374,7 +374,7 @@ pub mod printf { if let Start = state { match c { - '1'...'9' => { + '1'..='9' => { let end = at_next_cp_while(next, is_digit); match end.next_cp() { // Yes, this *is* the parameter. @@ -416,7 +416,7 @@ pub mod printf { state = WidthArg; move_to!(next); }, - '1' ... '9' => { + '1' ..= '9' => { let end = at_next_cp_while(next, is_digit); state = Prec; width = Some(Num::from_str(at.slice_between(end).unwrap(), None)); @@ -477,7 +477,7 @@ pub mod printf { } } }, - '0' ... '9' => { + '0' ..= '9' => { let end = at_next_cp_while(next, is_digit); state = Length; precision = Some(Num::from_str(at.slice_between(end).unwrap(), None)); @@ -570,7 +570,7 @@ pub mod printf { fn is_digit(c: char) -> bool { match c { - '0' ... '9' => true, + '0' ..= '9' => true, _ => false } } @@ -799,7 +799,7 @@ pub mod shell { let start = s.find('$')?; match s[start+1..].chars().next()? { '$' => return Some((Substitution::Escape, &s[start+2..])), - c @ '0' ... '9' => { + c @ '0' ..= '9' => { let n = (c as u8) - b'0'; return Some((Substitution::Ordinal(n), &s[start+2..])); }, @@ -836,14 +836,14 @@ pub mod shell { fn is_ident_head(c: char) -> bool { match c { - 'a' ... 'z' | 'A' ... 'Z' | '_' => true, + 'a' ..= 'z' | 'A' ..= 'Z' | '_' => true, _ => false } } fn is_ident_tail(c: char) -> bool { match c { - '0' ... '9' => true, + '0' ..= '9' => true, c => is_ident_head(c) } } diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index a4fb9571ecbe9..756e0c059a729 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -818,8 +818,8 @@ impl Encodable for FileMap { }; let bytes_per_diff: u8 = match max_line_length { - 0 ... 0xFF => 1, - 0x100 ... 0xFFFF => 2, + 0 ..= 0xFF => 1, + 0x100 ..= 0xFFFF => 2, _ => 4 }; diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index bd5ab92e8b078..b720d55594fd1 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -215,7 +215,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result { + ':' | '#' | ' ' | '.' | '0'..='9' => { let mut flags = Flags::new(); let mut fstate = FormatStateFlags; match cur { @@ -223,7 +223,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result flags.alternate = true, ' ' => flags.space = true, '.' => fstate = FormatStatePrecision, - '0'...'9' => { + '0'..='9' => { flags.width = cur as usize - '0' as usize; fstate = FormatStateWidth; } @@ -337,14 +337,14 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result { flags.space = true; } - (FormatStateFlags, '0'...'9') => { + (FormatStateFlags, '0'..='9') => { flags.width = cur as usize - '0' as usize; *fstate = FormatStateWidth; } (FormatStateFlags, '.') => { *fstate = FormatStatePrecision; } - (FormatStateWidth, '0'...'9') => { + (FormatStateWidth, '0'..='9') => { let old = flags.width; flags.width = flags.width * 10 + (cur as usize - '0' as usize); if flags.width < old { @@ -354,7 +354,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result { *fstate = FormatStatePrecision; } - (FormatStatePrecision, '0'...'9') => { + (FormatStatePrecision, '0'..='9') => { let old = flags.precision; flags.precision = flags.precision * 10 + (cur as usize - '0' as usize); if flags.precision < old { diff --git a/src/test/compile-fail/associated-path-shl.rs b/src/test/compile-fail/associated-path-shl.rs index 64afd702f5d82..7daf0d3c4e297 100644 --- a/src/test/compile-fail/associated-path-shl.rs +++ b/src/test/compile-fail/associated-path-shl.rs @@ -14,7 +14,7 @@ fn main() { let _: <::B>::C; //~ ERROR cannot find type `A` in this scope let _ = <::B>::C; //~ ERROR cannot find type `A` in this scope let <::B>::C; //~ ERROR cannot find type `A` in this scope - let 0 ... <::B>::C; //~ ERROR cannot find type `A` in this scope + let 0 ..= <::B>::C; //~ ERROR cannot find type `A` in this scope //~^ ERROR only char and numeric types are allowed in range patterns <::B>::C; //~ ERROR cannot find type `A` in this scope } diff --git a/src/test/compile-fail/issue-27895.rs b/src/test/compile-fail/issue-27895.rs index be76796c5c465..6063755c04f28 100644 --- a/src/test/compile-fail/issue-27895.rs +++ b/src/test/compile-fail/issue-27895.rs @@ -13,7 +13,7 @@ fn main() { let index = 6; match i { - 0...index => println!("winner"), + 0..=index => println!("winner"), //~^ ERROR runtime values cannot be referenced in patterns _ => println!("hello"), } diff --git a/src/test/compile-fail/issue-41255.rs b/src/test/compile-fail/issue-41255.rs index bdd502d442036..29912de37eb0e 100644 --- a/src/test/compile-fail/issue-41255.rs +++ b/src/test/compile-fail/issue-41255.rs @@ -27,7 +27,7 @@ fn main() { //~| WARNING hard error //~| ERROR floating-point types cannot be used in patterns //~| WARNING hard error - 39.0 ... 70.0 => {}, //~ ERROR floating-point types cannot be used in patterns + 39.0 ..= 70.0 => {}, //~ ERROR floating-point types cannot be used in patterns //~| WARNING hard error //~| ERROR floating-point types cannot be used in patterns //~| WARNING hard error diff --git a/src/test/compile-fail/match-range-fail-2.rs b/src/test/compile-fail/match-range-fail-2.rs index 91ad2b3507abd..b42e2ff919acb 100644 --- a/src/test/compile-fail/match-range-fail-2.rs +++ b/src/test/compile-fail/match-range-fail-2.rs @@ -12,7 +12,7 @@ fn main() { match 5 { - 6 ... 1 => { } + 6 ..= 1 => { } _ => { } }; //~^^^ ERROR lower range bound must be less than or equal to upper @@ -24,7 +24,7 @@ fn main() { //~^^^ ERROR lower range bound must be less than upper match 5u64 { - 0xFFFF_FFFF_FFFF_FFFF ... 1 => { } + 0xFFFF_FFFF_FFFF_FFFF ..= 1 => { } _ => { } }; //~^^^ ERROR lower range bound must be less than or equal to upper diff --git a/src/test/compile-fail/match-range-fail.rs b/src/test/compile-fail/match-range-fail.rs index f89b3e39390d3..ca99b0c7b8938 100644 --- a/src/test/compile-fail/match-range-fail.rs +++ b/src/test/compile-fail/match-range-fail.rs @@ -10,21 +10,21 @@ fn main() { match "wow" { - "bar" ... "foo" => { } + "bar" ..= "foo" => { } }; //~^^ ERROR only char and numeric types are allowed in range //~| start type: &'static str //~| end type: &'static str match "wow" { - 10 ... "what" => () + 10 ..= "what" => () }; //~^^ ERROR only char and numeric types are allowed in range //~| start type: {integer} //~| end type: &'static str match 5 { - 'c' ... 100 => { } + 'c' ..= 100 => { } _ => { } }; //~^^^ ERROR mismatched types diff --git a/src/test/compile-fail/non-constant-in-const-path.rs b/src/test/compile-fail/non-constant-in-const-path.rs index fe88ab4e11798..1aae25105a813 100644 --- a/src/test/compile-fail/non-constant-in-const-path.rs +++ b/src/test/compile-fail/non-constant-in-const-path.rs @@ -11,7 +11,7 @@ fn main() { let x = 0; match 1 { - 0 ... x => {} + 0 ..= x => {} //~^ ERROR runtime values cannot be referenced in patterns }; } diff --git a/src/test/compile-fail/patkind-litrange-no-expr.rs b/src/test/compile-fail/patkind-litrange-no-expr.rs index d57a23f26c479..8fef98f815f22 100644 --- a/src/test/compile-fail/patkind-litrange-no-expr.rs +++ b/src/test/compile-fail/patkind-litrange-no-expr.rs @@ -17,7 +17,7 @@ macro_rules! enum_number { fn foo(value: i32) -> Option<$name> { match value { $( $value => Some($name::$variant), )* // PatKind::Lit - $( $value ... 42 => Some($name::$variant), )* // PatKind::Range + $( $value ..= 42 => Some($name::$variant), )* // PatKind::Range _ => None } } @@ -32,4 +32,3 @@ enum_number!(Change { }); fn main() {} - diff --git a/src/test/compile-fail/qualified-path-params.rs b/src/test/compile-fail/qualified-path-params.rs index a7bc27e174918..018a3b2ae3258 100644 --- a/src/test/compile-fail/qualified-path-params.rs +++ b/src/test/compile-fail/qualified-path-params.rs @@ -29,6 +29,6 @@ fn main() { match 10 { ::A::f:: => {} //~^ ERROR expected unit struct/variant or constant, found method `<::A>::f` - 0 ... ::A::f:: => {} //~ ERROR only char and numeric types are allowed in range + 0 ..= ::A::f:: => {} //~ ERROR only char and numeric types are allowed in range } } diff --git a/src/test/compile-fail/refutable-pattern-errors.rs b/src/test/compile-fail/refutable-pattern-errors.rs index ce93e1875ae5a..7b4009481abd4 100644 --- a/src/test/compile-fail/refutable-pattern-errors.rs +++ b/src/test/compile-fail/refutable-pattern-errors.rs @@ -9,10 +9,10 @@ // except according to those terms. -fn func((1, (Some(1), 2...3)): (isize, (Option, isize))) { } +fn func((1, (Some(1), 2..=3)): (isize, (Option, isize))) { } //~^ ERROR refutable pattern in function argument: `(_, _)` not covered fn main() { - let (1, (Some(1), 2...3)) = (1, (None, 2)); + let (1, (Some(1), 2..=3)) = (1, (None, 2)); //~^ ERROR refutable pattern in local binding: `(_, _)` not covered } diff --git a/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs b/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs index 62cb870c7bb47..f9d1ce345352f 100644 --- a/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs +++ b/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs @@ -286,16 +286,16 @@ fn run() { // would require parens in patterns to allow disambiguation... reject_expr_parse("match 0 { - 0...#[attr] 10 => () + 0..=#[attr] 10 => () }"); reject_expr_parse("match 0 { - 0...#[attr] -10 => () + 0..=#[attr] -10 => () }"); reject_expr_parse("match 0 { - 0...-#[attr] 10 => () + 0..=-#[attr] 10 => () }"); reject_expr_parse("match 0 { - 0...#[attr] FOO => () + 0..=#[attr] FOO => () }"); // make sure we don't catch this bug again... diff --git a/src/test/run-pass/byte-literals.rs b/src/test/run-pass/byte-literals.rs index ad779d26f9e46..f5acb72429ae0 100644 --- a/src/test/run-pass/byte-literals.rs +++ b/src/test/run-pass/byte-literals.rs @@ -36,7 +36,7 @@ pub fn main() { } match 100 { - b'a' ... b'z' => {}, + b'a' ..= b'z' => {}, _ => panic!() } diff --git a/src/test/run-pass/inferred-suffix-in-pattern-range.rs b/src/test/run-pass/inferred-suffix-in-pattern-range.rs index 22369c77ed33f..89d26aade2ec3 100644 --- a/src/test/run-pass/inferred-suffix-in-pattern-range.rs +++ b/src/test/run-pass/inferred-suffix-in-pattern-range.rs @@ -12,21 +12,21 @@ pub fn main() { let x = 2; let x_message = match x { - 0 ... 1 => { "not many".to_string() } + 0 ..= 1 => { "not many".to_string() } _ => { "lots".to_string() } }; assert_eq!(x_message, "lots".to_string()); let y = 2; let y_message = match y { - 0 ... 1 => { "not many".to_string() } + 0 ..= 1 => { "not many".to_string() } _ => { "lots".to_string() } }; assert_eq!(y_message, "lots".to_string()); let z = 1u64; let z_message = match z { - 0 ... 1 => { "not many".to_string() } + 0 ..= 1 => { "not many".to_string() } _ => { "lots".to_string() } }; assert_eq!(z_message, "not many".to_string()); diff --git a/src/test/run-pass/issue-12582.rs b/src/test/run-pass/issue-12582.rs index 7bab2ddfed06b..b89964d968e84 100644 --- a/src/test/run-pass/issue-12582.rs +++ b/src/test/run-pass/issue-12582.rs @@ -16,7 +16,7 @@ pub fn main() { assert_eq!(3, match (x, y) { (1, 1) => 1, (2, 2) => 2, - (1...2, 2) => 3, + (1..=2, 2) => 3, _ => 4, }); @@ -24,7 +24,7 @@ pub fn main() { assert_eq!(3, match ((x, y),) { ((1, 1),) => 1, ((2, 2),) => 2, - ((1...2, 2),) => 3, + ((1..=2, 2),) => 3, _ => 4, }); } diff --git a/src/test/run-pass/issue-13027.rs b/src/test/run-pass/issue-13027.rs index d28ea94ec1a0d..2c460900ef628 100644 --- a/src/test/run-pass/issue-13027.rs +++ b/src/test/run-pass/issue-13027.rs @@ -30,7 +30,7 @@ pub fn main() { fn lit_shadow_range() { assert_eq!(2, match 1 { 1 if false => 1, - 1...2 => 2, + 1..=2 => 2, _ => 3 }); @@ -38,34 +38,34 @@ fn lit_shadow_range() { assert_eq!(2, match x+1 { 0 => 0, 1 if false => 1, - 1...2 => 2, + 1..=2 => 2, _ => 3 }); assert_eq!(2, match val() { 1 if false => 1, - 1...2 => 2, + 1..=2 => 2, _ => 3 }); assert_eq!(2, match CONST { 0 => 0, 1 if false => 1, - 1...2 => 2, + 1..=2 => 2, _ => 3 }); // value is out of the range of second arm, should match wildcard pattern assert_eq!(3, match 3 { 1 if false => 1, - 1...2 => 2, + 1..=2 => 2, _ => 3 }); } fn range_shadow_lit() { assert_eq!(2, match 1 { - 1...2 if false => 1, + 1..=2 if false => 1, 1 => 2, _ => 3 }); @@ -73,27 +73,27 @@ fn range_shadow_lit() { let x = 0; assert_eq!(2, match x+1 { 0 => 0, - 1...2 if false => 1, + 1..=2 if false => 1, 1 => 2, _ => 3 }); assert_eq!(2, match val() { - 1...2 if false => 1, + 1..=2 if false => 1, 1 => 2, _ => 3 }); assert_eq!(2, match CONST { 0 => 0, - 1...2 if false => 1, + 1..=2 if false => 1, 1 => 2, _ => 3 }); // ditto assert_eq!(3, match 3 { - 1...2 if false => 1, + 1..=2 if false => 1, 1 => 2, _ => 3 }); @@ -101,36 +101,36 @@ fn range_shadow_lit() { fn range_shadow_range() { assert_eq!(2, match 1 { - 0...2 if false => 1, - 1...3 => 2, + 0..=2 if false => 1, + 1..=3 => 2, _ => 3, }); let x = 0; assert_eq!(2, match x+1 { 100 => 0, - 0...2 if false => 1, - 1...3 => 2, + 0..=2 if false => 1, + 1..=3 => 2, _ => 3, }); assert_eq!(2, match val() { - 0...2 if false => 1, - 1...3 => 2, + 0..=2 if false => 1, + 1..=3 => 2, _ => 3, }); assert_eq!(2, match CONST { 100 => 0, - 0...2 if false => 1, - 1...3 => 2, + 0..=2 if false => 1, + 1..=3 => 2, _ => 3, }); // ditto assert_eq!(3, match 5 { - 0...2 if false => 1, - 1...3 => 2, + 0..=2 if false => 1, + 1..=3 => 2, _ => 3, }); } @@ -138,7 +138,7 @@ fn range_shadow_range() { fn multi_pats_shadow_lit() { assert_eq!(2, match 1 { 100 => 0, - 0 | 1...10 if false => 1, + 0 | 1..=10 if false => 1, 1 => 2, _ => 3, }); @@ -147,8 +147,8 @@ fn multi_pats_shadow_lit() { fn multi_pats_shadow_range() { assert_eq!(2, match 1 { 100 => 0, - 0 | 1...10 if false => 1, - 1...3 => 2, + 0 | 1..=10 if false => 1, + 1..=3 => 2, _ => 3, }); } @@ -157,7 +157,7 @@ fn lit_shadow_multi_pats() { assert_eq!(2, match 1 { 100 => 0, 1 if false => 1, - 0 | 1...10 => 2, + 0 | 1..=10 => 2, _ => 3, }); } @@ -165,8 +165,8 @@ fn lit_shadow_multi_pats() { fn range_shadow_multi_pats() { assert_eq!(2, match 1 { 100 => 0, - 1...3 if false => 1, - 0 | 1...10 => 2, + 1..=3 if false => 1, + 0 | 1..=10 => 2, _ => 3, }); } diff --git a/src/test/run-pass/issue-13867.rs b/src/test/run-pass/issue-13867.rs index e21070e2eafa1..bc28dc54de6f6 100644 --- a/src/test/run-pass/issue-13867.rs +++ b/src/test/run-pass/issue-13867.rs @@ -19,14 +19,14 @@ enum Foo { fn main() { let r = match (Foo::FooNullary, 'a') { - (Foo::FooUint(..), 'a'...'z') => 1, + (Foo::FooUint(..), 'a'..='z') => 1, (Foo::FooNullary, 'x') => 2, _ => 0 }; assert_eq!(r, 0); let r = match (Foo::FooUint(0), 'a') { - (Foo::FooUint(1), 'a'...'z') => 1, + (Foo::FooUint(1), 'a'..='z') => 1, (Foo::FooUint(..), 'x') => 2, (Foo::FooNullary, 'a') => 3, _ => 0 @@ -34,7 +34,7 @@ fn main() { assert_eq!(r, 0); let r = match ('a', Foo::FooUint(0)) { - ('a'...'z', Foo::FooUint(1)) => 1, + ('a'..='z', Foo::FooUint(1)) => 1, ('x', Foo::FooUint(..)) => 2, ('a', Foo::FooNullary) => 3, _ => 0 @@ -42,15 +42,15 @@ fn main() { assert_eq!(r, 0); let r = match ('a', 'a') { - ('a'...'z', 'b') => 1, - ('x', 'a'...'z') => 2, + ('a'..='z', 'b') => 1, + ('x', 'a'..='z') => 2, _ => 0 }; assert_eq!(r, 0); let r = match ('a', 'a') { - ('a'...'z', 'b') => 1, - ('x', 'a'...'z') => 2, + ('a'..='z', 'b') => 1, + ('x', 'a'..='z') => 2, ('a', 'a') => 3, _ => 0 }; diff --git a/src/test/run-pass/issue-18060.rs b/src/test/run-pass/issue-18060.rs index d6c9a92ca0291..322a3d8c9bb2e 100644 --- a/src/test/run-pass/issue-18060.rs +++ b/src/test/run-pass/issue-18060.rs @@ -11,7 +11,7 @@ // Regression test for #18060: match arms were matching in the wrong order. fn main() { - assert_eq!(2, match (1, 3) { (0, 2...5) => 1, (1, 3) => 2, (_, 2...5) => 3, (_, _) => 4 }); - assert_eq!(2, match (1, 3) { (1, 3) => 2, (_, 2...5) => 3, (_, _) => 4 }); - assert_eq!(2, match (1, 7) { (0, 2...5) => 1, (1, 7) => 2, (_, 2...5) => 3, (_, _) => 4 }); + assert_eq!(2, match (1, 3) { (0, 2..=5) => 1, (1, 3) => 2, (_, 2..=5) => 3, (_, _) => 4 }); + assert_eq!(2, match (1, 3) { (1, 3) => 2, (_, 2..=5) => 3, (_, _) => 4 }); + assert_eq!(2, match (1, 7) { (0, 2..=5) => 1, (1, 7) => 2, (_, 2..=5) => 3, (_, _) => 4 }); } diff --git a/src/test/run-pass/issue-18464.rs b/src/test/run-pass/issue-18464.rs index dff86bc1b4527..f4faab5e46853 100644 --- a/src/test/run-pass/issue-18464.rs +++ b/src/test/run-pass/issue-18464.rs @@ -15,7 +15,7 @@ const HIGH_RANGE: char = '9'; fn main() { match '5' { - LOW_RANGE...HIGH_RANGE => (), + LOW_RANGE..=HIGH_RANGE => (), _ => () }; } diff --git a/src/test/run-pass/issue-21475.rs b/src/test/run-pass/issue-21475.rs index 0666a1f133f2e..99839b56506f9 100644 --- a/src/test/run-pass/issue-21475.rs +++ b/src/test/run-pass/issue-21475.rs @@ -14,9 +14,9 @@ use m::{START, END}; fn main() { match 42 { - m::START...m::END => {}, - 0...m::END => {}, - m::START...59 => {}, + m::START..=m::END => {}, + 0..=m::END => {}, + m::START..=59 => {}, _ => {}, } } diff --git a/src/test/run-pass/issue-26251.rs b/src/test/run-pass/issue-26251.rs index 1e77d54fbf934..3735d36147d1f 100644 --- a/src/test/run-pass/issue-26251.rs +++ b/src/test/run-pass/issue-26251.rs @@ -12,9 +12,9 @@ fn main() { let x = 'a'; let y = match x { - 'a'...'b' if false => "one", + 'a'..='b' if false => "one", 'a' => "two", - 'a'...'b' => "three", + 'a'..='b' => "three", _ => panic!("what?"), }; diff --git a/src/test/run-pass/issue-35423.rs b/src/test/run-pass/issue-35423.rs index 35d0c305ed834..34cb2930db0cf 100644 --- a/src/test/run-pass/issue-35423.rs +++ b/src/test/run-pass/issue-35423.rs @@ -12,7 +12,7 @@ fn main () { let x = 4; match x { ref r if *r < 0 => println!("got negative num {} < 0", r), - e @ 1 ... 100 => println!("got number within range [1,100] {}", e), + e @ 1 ..= 100 => println!("got number within range [1,100] {}", e), _ => println!("no"), } } diff --git a/src/test/run-pass/issue-7222.rs b/src/test/run-pass/issue-7222.rs index 1bf343e23f0c1..3eb39ad6aad59 100644 --- a/src/test/run-pass/issue-7222.rs +++ b/src/test/run-pass/issue-7222.rs @@ -14,7 +14,7 @@ pub fn main() { const FOO: f64 = 10.0; match 0.0 { - 0.0 ... FOO => (), + 0.0 ..= FOO => (), _ => () } } diff --git a/src/test/run-pass/macro-literal.rs b/src/test/run-pass/macro-literal.rs index 0bcda7bc1447a..6d5e8bc97c0e9 100644 --- a/src/test/run-pass/macro-literal.rs +++ b/src/test/run-pass/macro-literal.rs @@ -41,18 +41,18 @@ macro_rules! mtester_dbg { } macro_rules! catch_range { - ($s:literal ... $e:literal) => { - &format!("macro caught literal: {} ... {}", $s, $e) + ($s:literal ..= $e:literal) => { + &format!("macro caught literal: {} ..= {}", $s, $e) }; - (($s:expr) ... ($e:expr)) => { // Must use ')' before '...' - &format!("macro caught expr: {} ... {}", $s, $e) + (($s:expr) ..= ($e:expr)) => { // Must use ')' before '..=' + &format!("macro caught expr: {} ..= {}", $s, $e) }; } macro_rules! pat_match { - ($s:literal ... $e:literal) => { + ($s:literal ..= $e:literal) => { match 3 { - $s ... $e => "literal, in range", + $s ..= $e => "literal, in range", _ => "literal, other", } }; @@ -115,22 +115,22 @@ pub fn main() { assert_eq!(mtester!('c'), "macro caught literal: c"); assert_eq!(mtester!(-1.2), "macro caught literal: -1.2"); assert_eq!(two_negative_literals!(-2 -3), "macro caught literals: -2, -3"); - assert_eq!(catch_range!(2 ... 3), "macro caught literal: 2 ... 3"); + assert_eq!(catch_range!(2 ..= 3), "macro caught literal: 2 ..= 3"); assert_eq!(match_attr!(#[attr] 1), "attr matched literal"); assert_eq!(test_user!(10, 20), "literal"); assert_eq!(mtester!(false), "macro caught literal: false"); assert_eq!(mtester!(true), "macro caught literal: true"); match_produced_attr!("a"); let _a = LiteralProduced; - assert_eq!(pat_match!(1 ... 3), "literal, in range"); - assert_eq!(pat_match!(4 ... 6), "literal, other"); + assert_eq!(pat_match!(1 ..= 3), "literal, in range"); + assert_eq!(pat_match!(4 ..= 6), "literal, other"); // Cases where 'expr' catches assert_eq!(mtester!((-1.2)), "macro caught expr: -1.2"); assert_eq!(only_expr!(-1.2), "macro caught expr: -1.2"); assert_eq!(mtester!((1 + 3)), "macro caught expr: 4"); assert_eq!(mtester_dbg!(()), "macro caught expr: ()"); - assert_eq!(catch_range!((1 + 1) ... (2 + 2)), "macro caught expr: 2 ... 4"); + assert_eq!(catch_range!((1 + 1) ..= (2 + 2)), "macro caught expr: 2 ..= 4"); assert_eq!(match_attr!(#[attr] (1 + 2)), "attr matched expr"); assert_eq!(test_user!(10, (20 + 2)), "expr"); diff --git a/src/test/run-pass/match-range-infer.rs b/src/test/run-pass/match-range-infer.rs index 74f513ef0814f..cf07345d3433a 100644 --- a/src/test/run-pass/match-range-infer.rs +++ b/src/test/run-pass/match-range-infer.rs @@ -12,15 +12,15 @@ pub fn main() { match 1 { - 1 ... 3 => {} + 1 ..= 3 => {} _ => panic!("should match range") } match 1 { - 1 ... 3u16 => {} + 1 ..= 3u16 => {} _ => panic!("should match range with inferred start type") } match 1 { - 1u16 ... 3 => {} + 1u16 ..= 3 => {} _ => panic!("should match range with inferred end type") } } diff --git a/src/test/run-pass/match-range-static.rs b/src/test/run-pass/match-range-static.rs index 9aafcda1b02ad..b63ca7defd61a 100644 --- a/src/test/run-pass/match-range-static.rs +++ b/src/test/run-pass/match-range-static.rs @@ -15,7 +15,7 @@ const e: isize = 42; pub fn main() { match 7 { - s...e => (), + s..=e => (), _ => (), } } diff --git a/src/test/run-pass/match-range.rs b/src/test/run-pass/match-range.rs index cf695a77ce1f1..859edb80a0743 100644 --- a/src/test/run-pass/match-range.rs +++ b/src/test/run-pass/match-range.rs @@ -12,7 +12,7 @@ pub fn main() { match 5_usize { - 1_usize...5_usize => {} + 1_usize..=5_usize => {} _ => panic!("should match range"), } match 1_usize { @@ -20,7 +20,7 @@ pub fn main() { _ => panic!("should match range start"), } match 5_usize { - 6_usize...7_usize => panic!("shouldn't match range"), + 6_usize..=7_usize => panic!("shouldn't match range"), _ => {} } match 7_usize { @@ -29,23 +29,23 @@ pub fn main() { } match 5_usize { 1_usize => panic!("should match non-first range"), - 2_usize...6_usize => {} + 2_usize..=6_usize => {} _ => panic!("math is broken") } match 'c' { - 'a'...'z' => {} + 'a'..='z' => {} _ => panic!("should suppport char ranges") } match -3 { - -7...5 => {} + -7..=5 => {} _ => panic!("should match signed range") } match 3.0f64 { - 1.0...5.0 => {} + 1.0..=5.0 => {} _ => panic!("should match float range") } match -1.5f64 { - -3.6...3.6 => {} + -3.6..=3.6 => {} _ => panic!("should match negative float range") } match 3.5 { diff --git a/src/test/run-pass/rfc-2005-default-binding-mode/range.rs b/src/test/run-pass/rfc-2005-default-binding-mode/range.rs index 2292d97eaf4e5..f38bd2de86971 100644 --- a/src/test/run-pass/rfc-2005-default-binding-mode/range.rs +++ b/src/test/run-pass/rfc-2005-default-binding-mode/range.rs @@ -11,8 +11,8 @@ pub fn main() { let i = 5; match &&&&i { - 1 ... 3 => panic!(), - 3 ... 8 => {}, + 1 ..= 3 => panic!(), + 3 ..= 8 => {}, _ => panic!(), } } diff --git a/src/test/ui/check_match/issue-43253.rs b/src/test/ui/check_match/issue-43253.rs index a01ebb768b49b..aace8c0c02b20 100644 --- a/src/test/ui/check_match/issue-43253.rs +++ b/src/test/ui/check_match/issue-43253.rs @@ -23,13 +23,13 @@ fn main() { match 10 { 1..10 => {}, - 9...10 => {}, + 9..=10 => {}, _ => {}, } match 10 { 1..10 => {}, - 10...10 => {}, + 10..=10 => {}, _ => {}, } @@ -42,13 +42,13 @@ fn main() { match 10 { 1..10 => {}, - 8...9 => {}, + 8..=9 => {}, _ => {}, } match 10 { 1..10 => {}, - 9...9 => {}, + 9..=9 => {}, _ => {}, } } diff --git a/src/test/ui/check_match/issue-43253.stderr b/src/test/ui/check_match/issue-43253.stderr index 111f4e44ee9c1..2af6a2a636841 100644 --- a/src/test/ui/check_match/issue-43253.stderr +++ b/src/test/ui/check_match/issue-43253.stderr @@ -13,12 +13,12 @@ LL | #![warn(unreachable_patterns)] warning: unreachable pattern --> $DIR/issue-43253.rs:45:9 | -LL | 8...9 => {}, +LL | 8..=9 => {}, | ^^^^^ warning: unreachable pattern --> $DIR/issue-43253.rs:51:9 | -LL | 9...9 => {}, +LL | 9..=9 => {}, | ^^^^^ diff --git a/src/test/ui/const-eval/const_signed_pat.rs b/src/test/ui/const-eval/const_signed_pat.rs index f53d6f3fa0a15..008ebf13c6354 100644 --- a/src/test/ui/const-eval/const_signed_pat.rs +++ b/src/test/ui/const-eval/const_signed_pat.rs @@ -13,7 +13,7 @@ fn main() { const MIN: i8 = -5; match 5i8 { - MIN...-1 => {}, + MIN..=-1 => {}, _ => {}, } } diff --git a/src/test/ui/const-eval/ref_to_int_match.rs b/src/test/ui/const-eval/ref_to_int_match.rs index 4c5fc6c379762..8ad7f11f0cee8 100644 --- a/src/test/ui/const-eval/ref_to_int_match.rs +++ b/src/test/ui/const-eval/ref_to_int_match.rs @@ -11,8 +11,8 @@ fn main() { let n: Int = 40; match n { - 0...10 => {}, - 10...BAR => {}, //~ ERROR lower range bound must be less than or equal to upper + 0..=10 => {}, + 10..=BAR => {}, //~ ERROR lower range bound must be less than or equal to upper _ => {}, } } diff --git a/src/test/ui/const-eval/ref_to_int_match.stderr b/src/test/ui/const-eval/ref_to_int_match.stderr index eef7b6df252fe..64ea57702d706 100644 --- a/src/test/ui/const-eval/ref_to_int_match.stderr +++ b/src/test/ui/const-eval/ref_to_int_match.stderr @@ -1,7 +1,7 @@ error[E0030]: lower range bound must be less than or equal to upper --> $DIR/ref_to_int_match.rs:15:9 | -LL | 10...BAR => {}, //~ ERROR lower range bound must be less than or equal to upper +LL | 10..=BAR => {}, //~ ERROR lower range bound must be less than or equal to upper | ^^ lower bound larger than upper bound error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0029-teach.rs b/src/test/ui/error-codes/E0029-teach.rs index 1bc2c2d58b194..328c46311af56 100644 --- a/src/test/ui/error-codes/E0029-teach.rs +++ b/src/test/ui/error-codes/E0029-teach.rs @@ -14,7 +14,7 @@ fn main() { let s = "hoho"; match s { - "hello" ... "world" => {} + "hello" ..= "world" => {} //~^ ERROR only char and numeric types are allowed in range patterns _ => {} } diff --git a/src/test/ui/error-codes/E0029-teach.stderr b/src/test/ui/error-codes/E0029-teach.stderr index 4bb71f68a98b9..bb4fac9a4cb4c 100644 --- a/src/test/ui/error-codes/E0029-teach.stderr +++ b/src/test/ui/error-codes/E0029-teach.stderr @@ -1,7 +1,7 @@ error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/E0029-teach.rs:17:9 | -LL | "hello" ... "world" => {} +LL | "hello" ..= "world" => {} | ^^^^^^^^^^^^^^^^^^^ ranges require char or numeric types | = note: start type: &'static str diff --git a/src/test/ui/error-codes/E0029.rs b/src/test/ui/error-codes/E0029.rs index 29b6fe4411358..c89b4f5b3771f 100644 --- a/src/test/ui/error-codes/E0029.rs +++ b/src/test/ui/error-codes/E0029.rs @@ -12,7 +12,7 @@ fn main() { let s = "hoho"; match s { - "hello" ... "world" => {} + "hello" ..= "world" => {} //~^ ERROR only char and numeric types are allowed in range patterns _ => {} } diff --git a/src/test/ui/error-codes/E0029.stderr b/src/test/ui/error-codes/E0029.stderr index bcdfa38711107..d25666f9cf84a 100644 --- a/src/test/ui/error-codes/E0029.stderr +++ b/src/test/ui/error-codes/E0029.stderr @@ -1,7 +1,7 @@ error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/E0029.rs:15:9 | -LL | "hello" ... "world" => {} +LL | "hello" ..= "world" => {} | ^^^^^^^^^^^^^^^^^^^ ranges require char or numeric types | = note: start type: &'static str diff --git a/src/test/ui/error-codes/E0030-teach.rs b/src/test/ui/error-codes/E0030-teach.rs index 2af32eda62be9..cf860cea24c86 100644 --- a/src/test/ui/error-codes/E0030-teach.rs +++ b/src/test/ui/error-codes/E0030-teach.rs @@ -12,7 +12,7 @@ fn main() { match 5u32 { - 1000 ... 5 => {} + 1000 ..= 5 => {} //~^ ERROR lower range bound must be less than or equal to upper } } diff --git a/src/test/ui/error-codes/E0030-teach.stderr b/src/test/ui/error-codes/E0030-teach.stderr index 8b262d5b296b6..2a7243a95690e 100644 --- a/src/test/ui/error-codes/E0030-teach.stderr +++ b/src/test/ui/error-codes/E0030-teach.stderr @@ -1,7 +1,7 @@ error[E0030]: lower range bound must be less than or equal to upper --> $DIR/E0030-teach.rs:15:9 | -LL | 1000 ... 5 => {} +LL | 1000 ..= 5 => {} | ^^^^ lower bound larger than upper bound | = note: When matching against a range, the compiler verifies that the range is non-empty. Range patterns include both end-points, so this is equivalent to requiring the start of the range to be less than or equal to the end of the range. diff --git a/src/test/ui/error-codes/E0030.rs b/src/test/ui/error-codes/E0030.rs index ef3bded4beffb..e147dd932b0dd 100644 --- a/src/test/ui/error-codes/E0030.rs +++ b/src/test/ui/error-codes/E0030.rs @@ -11,7 +11,7 @@ fn main() { match 5u32 { - 1000 ... 5 => {} + 1000 ..= 5 => {} //~^ ERROR lower range bound must be less than or equal to upper } } diff --git a/src/test/ui/error-codes/E0030.stderr b/src/test/ui/error-codes/E0030.stderr index 0949cfb50b680..020655ee45b54 100644 --- a/src/test/ui/error-codes/E0030.stderr +++ b/src/test/ui/error-codes/E0030.stderr @@ -1,7 +1,7 @@ error[E0030]: lower range bound must be less than or equal to upper --> $DIR/E0030.rs:14:9 | -LL | 1000 ... 5 => {} +LL | 1000 ..= 5 => {} | ^^^^ lower bound larger than upper bound error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0308-4.rs b/src/test/ui/error-codes/E0308-4.rs index bb4cd1434167b..106c55817c11a 100644 --- a/src/test/ui/error-codes/E0308-4.rs +++ b/src/test/ui/error-codes/E0308-4.rs @@ -11,7 +11,7 @@ fn main() { let x = 1u8; match x { - 0u8...3i8 => (), //~ ERROR E0308 + 0u8..=3i8 => (), //~ ERROR E0308 _ => () } } diff --git a/src/test/ui/error-codes/E0308-4.stderr b/src/test/ui/error-codes/E0308-4.stderr index 31875349bace0..8943c7332e94d 100644 --- a/src/test/ui/error-codes/E0308-4.stderr +++ b/src/test/ui/error-codes/E0308-4.stderr @@ -1,7 +1,7 @@ error[E0308]: mismatched types --> $DIR/E0308-4.rs:14:9 | -LL | 0u8...3i8 => (), //~ ERROR E0308 +LL | 0u8..=3i8 => (), //~ ERROR E0308 | ^^^^^^^^^ expected u8, found i8 error: aborting due to previous error From 3fb76f4027596f524403e6eea60e9531e70e9460 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Mon, 28 May 2018 19:32:03 -0700 Subject: [PATCH 2/3] =?UTF-8?q?inclusive=20range=20syntax=20lint=20(`...`?= =?UTF-8?q?=20=E2=86=92=20`..=3D`)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our implementation ends up changing the `PatKind::Range` variant in the AST to take a `Spanned` instead of just a `RangeEnd`, because the alternative would be to try to infer the span of the range operator from the spans of the start and end subexpressions, which is both hideous and nontrivial to get right (whereas getting the change to the AST right was a simple game of type tennis). This is concerning #51043. --- src/librustc/hir/lowering.rs | 2 +- src/librustc_lint/builtin.rs | 38 +++++++++++++++++++ src/librustc_lint/lib.rs | 4 +- src/libsyntax/ast.rs | 2 +- src/libsyntax/feature_gate.rs | 3 +- src/libsyntax/fold.rs | 4 +- src/libsyntax/parse/parser.rs | 33 ++++++++++------ src/libsyntax/print/pprust.rs | 4 +- .../lint/inclusive-range-pattern-syntax.fixed | 23 +++++++++++ .../ui/lint/inclusive-range-pattern-syntax.rs | 23 +++++++++++ .../inclusive-range-pattern-syntax.stderr | 12 ++++++ .../ui/range-inclusive-pattern-precedence.rs | 6 +++ .../range-inclusive-pattern-precedence.stderr | 22 ++++++++++- 13 files changed, 154 insertions(+), 22 deletions(-) create mode 100644 src/test/ui/lint/inclusive-range-pattern-syntax.fixed create mode 100644 src/test/ui/lint/inclusive-range-pattern-syntax.rs create mode 100644 src/test/ui/lint/inclusive-range-pattern-syntax.stderr diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 484c41b3a7996..110ebf6b215a1 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -3356,7 +3356,7 @@ impl<'a> LoweringContext<'a> { PatKind::Ref(ref inner, mutbl) => { hir::PatKind::Ref(self.lower_pat(inner), self.lower_mutability(mutbl)) } - PatKind::Range(ref e1, ref e2, ref end) => hir::PatKind::Range( + PatKind::Range(ref e1, ref e2, Spanned { node: ref end, .. }) => hir::PatKind::Range( P(self.lower_expr(e1)), P(self.lower_expr(e2)), self.lower_range_end(end), diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index d6120ab207924..dfbfcfccf7c89 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -43,6 +43,7 @@ use std::collections::HashSet; use syntax::ast; use syntax::attr; +use syntax::codemap::Spanned; use syntax::edition::Edition; use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes}; use syntax_pos::{BytePos, Span, SyntaxContext}; @@ -1669,6 +1670,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints { } } + /// Does nothing as a lint pass, but registers some `Lint`s /// which are used by other parts of the compiler. #[derive(Copy, Clone)] @@ -1701,3 +1703,39 @@ impl LintPass for SoftLints { ) } } + + +declare_lint! { + pub ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, + Allow, + "`...` range patterns are deprecated" +} + + +pub struct EllipsisInclusiveRangePatterns; + +impl LintPass for EllipsisInclusiveRangePatterns { + fn get_lints(&self) -> LintArray { + lint_array!(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS) + } +} + +impl EarlyLintPass for EllipsisInclusiveRangePatterns { + fn check_pat(&mut self, cx: &EarlyContext, pat: &ast::Pat) { + use self::ast::{PatKind, RangeEnd, RangeSyntax}; + + if let PatKind::Range( + _, _, Spanned { span, node: RangeEnd::Included(RangeSyntax::DotDotDot) } + ) = pat.node { + let msg = "`...` range patterns are deprecated"; + let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, span, msg); + err.span_suggestion_short_with_applicability( + span, "use `..=` for an inclusive range", "..=".to_owned(), + // FIXME: outstanding problem with precedence in ref patterns: + // https://github.com/rust-lang/rust/issues/51043#issuecomment-392252285 + Applicability::MaybeIncorrect + ); + err.emit() + } + } +} diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 1d443258dc642..ba373b5c0e89d 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -111,6 +111,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { AnonymousParameters, UnusedDocComment, BadRepr, + EllipsisInclusiveRangePatterns, ); add_early_builtin_with_new!(sess, @@ -188,7 +189,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { "rust_2018_idioms", BARE_TRAIT_OBJECTS, UNREACHABLE_PUB, - UNUSED_EXTERN_CRATES); + UNUSED_EXTERN_CRATES, + ELLIPSIS_INCLUSIVE_RANGE_PATTERNS); // Guidelines for creating a future incompatibility lint: // diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a09055e6c4aa5..53465c071f33a 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -617,7 +617,7 @@ pub enum PatKind { /// A literal Lit(P), /// A range pattern, e.g. `1...2`, `1..=2` or `1..2` - Range(P, P, RangeEnd), + Range(P, P, Spanned), /// `[a, b, ..i, y, z]` is represented as: /// `PatKind::Slice(box [a, b], Some(i), box [y, z])` Slice(Vec>, Option>, Vec>), diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 51d7a23699544..c813ec1977b88 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -28,6 +28,7 @@ use self::AttributeGate::*; use rustc_target::spec::abi::Abi; use ast::{self, NodeId, PatKind, RangeEnd}; use attr; +use codemap::Spanned; use edition::{ALL_EDITIONS, Edition}; use syntax_pos::{Span, DUMMY_SP}; use errors::{DiagnosticBuilder, Handler, FatalError}; @@ -1752,7 +1753,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { pattern.span, "box pattern syntax is experimental"); } - PatKind::Range(_, _, RangeEnd::Excluded) => { + PatKind::Range(_, _, Spanned { node: RangeEnd::Excluded, .. }) => { gate_feature_post!(&self, exclusive_range_pattern, pattern.span, "exclusive range pattern syntax is experimental"); } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index ffea713f4ec76..712d00fde32db 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1137,10 +1137,10 @@ pub fn noop_fold_pat(p: P, folder: &mut T) -> P { } PatKind::Box(inner) => PatKind::Box(folder.fold_pat(inner)), PatKind::Ref(inner, mutbl) => PatKind::Ref(folder.fold_pat(inner), mutbl), - PatKind::Range(e1, e2, end) => { + PatKind::Range(e1, e2, Spanned { span, node: end }) => { PatKind::Range(folder.fold_expr(e1), folder.fold_expr(e2), - folder.fold_range_end(end)) + Spanned { span, node: folder.fold_range_end(end) }) }, PatKind::Slice(before, slice, after) => { PatKind::Slice(before.move_map(|x| folder.fold_pat(x)), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 955bdbdcf9177..21bd6c083244d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4024,12 +4024,14 @@ impl<'a> Parser<'a> { _ => panic!("can only parse `..`/`...`/`..=` for ranges \ (checked above)"), }; + let op_span = self.span; // Parse range let span = lo.to(self.prev_span); let begin = self.mk_expr(span, ExprKind::Path(qself, path), ThinVec::new()); self.bump(); let end = self.parse_pat_range_end()?; - pat = PatKind::Range(begin, end, end_kind); + let op = Spanned { span: op_span, node: end_kind }; + pat = PatKind::Range(begin, end, op); } token::OpenDelim(token::Brace) => { if qself.is_some() { @@ -4065,17 +4067,22 @@ impl<'a> Parser<'a> { // Try to parse everything else as literal with optional minus match self.parse_literal_maybe_minus() { Ok(begin) => { - if self.eat(&token::DotDotDot) { + let op_span = self.span; + if self.check(&token::DotDot) || self.check(&token::DotDotEq) || + self.check(&token::DotDotDot) { + let end_kind = if self.eat(&token::DotDotDot) { + RangeEnd::Included(RangeSyntax::DotDotDot) + } else if self.eat(&token::DotDotEq) { + RangeEnd::Included(RangeSyntax::DotDotEq) + } else if self.eat(&token::DotDot) { + RangeEnd::Excluded + } else { + panic!("impossible case: we already matched \ + on a range-operator token") + }; let end = self.parse_pat_range_end()?; - pat = PatKind::Range(begin, end, - RangeEnd::Included(RangeSyntax::DotDotDot)); - } else if self.eat(&token::DotDotEq) { - let end = self.parse_pat_range_end()?; - pat = PatKind::Range(begin, end, - RangeEnd::Included(RangeSyntax::DotDotEq)); - } else if self.eat(&token::DotDot) { - let end = self.parse_pat_range_end()?; - pat = PatKind::Range(begin, end, RangeEnd::Excluded); + let op = Spanned { span: op_span, node: end_kind }; + pat = PatKind::Range(begin, end, op); } else { pat = PatKind::Lit(begin); } @@ -4096,7 +4103,9 @@ impl<'a> Parser<'a> { if !allow_range_pat { match pat.node { - PatKind::Range(_, _, RangeEnd::Included(RangeSyntax::DotDotDot)) => {} + PatKind::Range( + _, _, Spanned { node: RangeEnd::Included(RangeSyntax::DotDotDot), .. } + ) => {}, PatKind::Range(..) => { let mut err = self.struct_span_err( pat.span, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 70c4324a056a0..3359225e15965 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -16,7 +16,7 @@ use ast::{SelfKind, GenericBound, TraitBoundModifier}; use ast::{Attribute, MacDelimiter, GenericArg}; use util::parser::{self, AssocOp, Fixity}; use attr; -use codemap::{self, CodeMap}; +use codemap::{self, CodeMap, Spanned}; use syntax_pos::{self, BytePos}; use syntax_pos::hygiene::{Mark, SyntaxContext}; use parse::token::{self, BinOpToken, Token}; @@ -2624,7 +2624,7 @@ impl<'a> State<'a> { self.print_pat(inner)?; } PatKind::Lit(ref e) => self.print_expr(&**e)?, - PatKind::Range(ref begin, ref end, ref end_kind) => { + PatKind::Range(ref begin, ref end, Spanned { node: ref end_kind, .. }) => { self.print_expr(begin)?; self.s.space()?; match *end_kind { diff --git a/src/test/ui/lint/inclusive-range-pattern-syntax.fixed b/src/test/ui/lint/inclusive-range-pattern-syntax.fixed new file mode 100644 index 0000000000000..d16859df79e25 --- /dev/null +++ b/src/test/ui/lint/inclusive-range-pattern-syntax.fixed @@ -0,0 +1,23 @@ +// Copyright 2018 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. + +// compile-pass +// run-rustfix + +#![warn(ellipsis_inclusive_range_patterns)] + +fn main() { + let despondency = 2; + match despondency { + 1..=2 => {} + //~^ WARN `...` range patterns are deprecated + _ => {} + } +} diff --git a/src/test/ui/lint/inclusive-range-pattern-syntax.rs b/src/test/ui/lint/inclusive-range-pattern-syntax.rs new file mode 100644 index 0000000000000..9d418aec0858f --- /dev/null +++ b/src/test/ui/lint/inclusive-range-pattern-syntax.rs @@ -0,0 +1,23 @@ +// Copyright 2018 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. + +// compile-pass +// run-rustfix + +#![warn(ellipsis_inclusive_range_patterns)] + +fn main() { + let despondency = 2; + match despondency { + 1...2 => {} + //~^ WARN `...` range patterns are deprecated + _ => {} + } +} diff --git a/src/test/ui/lint/inclusive-range-pattern-syntax.stderr b/src/test/ui/lint/inclusive-range-pattern-syntax.stderr new file mode 100644 index 0000000000000..de04fed589b23 --- /dev/null +++ b/src/test/ui/lint/inclusive-range-pattern-syntax.stderr @@ -0,0 +1,12 @@ +warning: `...` range patterns are deprecated + --> $DIR/inclusive-range-pattern-syntax.rs:19:10 + | +LL | 1...2 => {} + | ^^^ help: use `..=` for an inclusive range + | +note: lint level defined here + --> $DIR/inclusive-range-pattern-syntax.rs:14:9 + | +LL | #![warn(ellipsis_inclusive_range_patterns)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/src/test/ui/range-inclusive-pattern-precedence.rs b/src/test/ui/range-inclusive-pattern-precedence.rs index 67a0f79ca6b82..ce0c9947a05f6 100644 --- a/src/test/ui/range-inclusive-pattern-precedence.rs +++ b/src/test/ui/range-inclusive-pattern-precedence.rs @@ -16,10 +16,14 @@ // older ... syntax is still allowed as a stability guarantee. #![feature(box_patterns)] +#![warn(ellipsis_inclusive_range_patterns)] + pub fn main() { match &12 { &0...9 => {} + //~^ WARN `...` range patterns are deprecated + //~| HELP use `..=` for an inclusive range &10..=15 => {} //~^ ERROR the range pattern here has ambiguous interpretation //~^^ HELP add parentheses to clarify the precedence @@ -29,6 +33,8 @@ pub fn main() { match Box::new(12) { box 0...9 => {} + //~^ WARN `...` range patterns are deprecated + //~| HELP use `..=` for an inclusive range box 10..=15 => {} //~^ ERROR the range pattern here has ambiguous interpretation //~^^ HELP add parentheses to clarify the precedence diff --git a/src/test/ui/range-inclusive-pattern-precedence.stderr b/src/test/ui/range-inclusive-pattern-precedence.stderr index 99e0d739036b0..cd5ce3035c683 100644 --- a/src/test/ui/range-inclusive-pattern-precedence.stderr +++ b/src/test/ui/range-inclusive-pattern-precedence.stderr @@ -1,14 +1,32 @@ error: the range pattern here has ambiguous interpretation - --> $DIR/range-inclusive-pattern-precedence.rs:23:10 + --> $DIR/range-inclusive-pattern-precedence.rs:27:10 | LL | &10..=15 => {} | ^^^^^^^ help: add parentheses to clarify the precedence: `(10 ..=15)` error: the range pattern here has ambiguous interpretation - --> $DIR/range-inclusive-pattern-precedence.rs:32:13 + --> $DIR/range-inclusive-pattern-precedence.rs:38:13 | LL | box 10..=15 => {} | ^^^^^^^ help: add parentheses to clarify the precedence: `(10 ..=15)` +warning: `...` range patterns are deprecated + --> $DIR/range-inclusive-pattern-precedence.rs:24:11 + | +LL | &0...9 => {} + | ^^^ help: use `..=` for an inclusive range + | +note: lint level defined here + --> $DIR/range-inclusive-pattern-precedence.rs:19:9 + | +LL | #![warn(ellipsis_inclusive_range_patterns)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: `...` range patterns are deprecated + --> $DIR/range-inclusive-pattern-precedence.rs:35:14 + | +LL | box 0...9 => {} + | ^^^ help: use `..=` for an inclusive range + error: aborting due to 2 previous errors From 64365e46f2675403babb2669d60d418fae3e0a7c Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sun, 3 Jun 2018 12:42:05 -0700 Subject: [PATCH 3/3] driveby status update to 2015 comment about parens in patterns --- src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs b/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs index f9d1ce345352f..2ef7eba6c05d1 100644 --- a/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs +++ b/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs @@ -284,6 +284,8 @@ fn run() { // FIXME: Allow attributes in pattern constexprs? // would require parens in patterns to allow disambiguation... + // —which is now available under the `pattern_parentheses` feature gate + // (tracking issue #51087) reject_expr_parse("match 0 { 0..=#[attr] 10 => ()