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).
This commit is contained in:
Zack M. Davis 2018-05-28 19:42:11 -07:00
parent 764232cb2a
commit 057715557b
65 changed files with 217 additions and 218 deletions

View file

@ -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'\'' => ([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), _ => ([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 { fn hexify(b: u8) -> u8 {
match b { match b {
0 ... 9 => b'0' + b, 0 ..= 9 => b'0' + b,
_ => b'a' + b - 10, _ => b'a' + b - 10,
} }
} }

View file

@ -64,7 +64,7 @@ impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
} }
} }
macro_rules! continuation_byte { macro_rules! continuation_byte {
() => { continuation_byte!(0x80...0xBF) }; () => { continuation_byte!(0x80..=0xBF) };
($range: pat) => { ($range: pat) => {
match self.0.peek() { match self.0.peek() {
Some(&byte @ $range) => { Some(&byte @ $range) => {
@ -77,35 +77,35 @@ impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
} }
match first_byte { match first_byte {
0x00...0x7F => { 0x00..=0x7F => {
first_byte!(0b1111_1111); first_byte!(0b1111_1111);
} }
0xC2...0xDF => { 0xC2..=0xDF => {
first_byte!(0b0001_1111); first_byte!(0b0001_1111);
continuation_byte!(); continuation_byte!();
} }
0xE0 => { 0xE0 => {
first_byte!(0b0000_1111); first_byte!(0b0000_1111);
continuation_byte!(0xA0...0xBF); // 0x80...0x9F here are overlong continuation_byte!(0xA0..=0xBF); // 0x80..=0x9F here are overlong
continuation_byte!(); continuation_byte!();
} }
0xE1...0xEC | 0xEE...0xEF => { 0xE1..=0xEC | 0xEE..=0xEF => {
first_byte!(0b0000_1111); first_byte!(0b0000_1111);
continuation_byte!(); continuation_byte!();
continuation_byte!(); continuation_byte!();
} }
0xED => { 0xED => {
first_byte!(0b0000_1111); first_byte!(0b0000_1111);
continuation_byte!(0x80...0x9F); // 0xA0..0xBF here are surrogates continuation_byte!(0x80..=0x9F); // 0xA0..0xBF here are surrogates
continuation_byte!(); continuation_byte!();
} }
0xF0 => { 0xF0 => {
first_byte!(0b0000_0111); 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!();
continuation_byte!(); continuation_byte!();
} }
0xF1...0xF3 => { 0xF1..=0xF3 => {
first_byte!(0b0000_0111); first_byte!(0b0000_0111);
continuation_byte!(); continuation_byte!();
continuation_byte!(); continuation_byte!();
@ -113,7 +113,7 @@ impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
} }
0xF4 => { 0xF4 => {
first_byte!(0b0000_0111); 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!();
continuation_byte!(); continuation_byte!();
} }

View file

@ -125,9 +125,9 @@ impl char {
panic!("to_digit: radix is too high (maximum 36)"); panic!("to_digit: radix is too high (maximum 36)");
} }
let val = match self { let val = match self {
'0' ... '9' => self as u32 - '0' as u32, '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,
'A' ... 'Z' => self as u32 - 'A' as u32 + 10, 'A' ..= 'Z' => self as u32 - 'A' as u32 + 10,
_ => return None, _ => return None,
}; };
if val < radix { Some(val) } if val < radix { Some(val) }
@ -305,7 +305,7 @@ impl char {
'\r' => EscapeDefaultState::Backslash('r'), '\r' => EscapeDefaultState::Backslash('r'),
'\n' => EscapeDefaultState::Backslash('n'), '\n' => EscapeDefaultState::Backslash('n'),
'\\' | '\'' | '"' => EscapeDefaultState::Backslash(self), '\\' | '\'' | '"' => EscapeDefaultState::Backslash(self),
'\x20' ... '\x7e' => EscapeDefaultState::Char(self), '\x20' ..= '\x7e' => EscapeDefaultState::Char(self),
_ => EscapeDefaultState::Unicode(self.escape_unicode()) _ => EscapeDefaultState::Unicode(self.escape_unicode())
}; };
EscapeDefault { state: init_state } EscapeDefault { state: init_state }
@ -543,7 +543,7 @@ impl char {
#[inline] #[inline]
pub fn is_alphabetic(self) -> bool { pub fn is_alphabetic(self) -> bool {
match self { match self {
'a'...'z' | 'A'...'Z' => true, 'a'..='z' | 'A'..='Z' => true,
c if c > '\x7f' => derived_property::Alphabetic(c), c if c > '\x7f' => derived_property::Alphabetic(c),
_ => false, _ => false,
} }
@ -599,7 +599,7 @@ impl char {
#[inline] #[inline]
pub fn is_lowercase(self) -> bool { pub fn is_lowercase(self) -> bool {
match self { match self {
'a'...'z' => true, 'a'..='z' => true,
c if c > '\x7f' => derived_property::Lowercase(c), c if c > '\x7f' => derived_property::Lowercase(c),
_ => false, _ => false,
} }
@ -627,7 +627,7 @@ impl char {
#[inline] #[inline]
pub fn is_uppercase(self) -> bool { pub fn is_uppercase(self) -> bool {
match self { match self {
'A'...'Z' => true, 'A'..='Z' => true,
c if c > '\x7f' => derived_property::Uppercase(c), c if c > '\x7f' => derived_property::Uppercase(c),
_ => false, _ => false,
} }
@ -654,7 +654,7 @@ impl char {
#[inline] #[inline]
pub fn is_whitespace(self) -> bool { pub fn is_whitespace(self) -> bool {
match self { match self {
' ' | '\x09'...'\x0d' => true, ' ' | '\x09'..='\x0d' => true,
c if c > '\x7f' => property::White_Space(c), c if c > '\x7f' => property::White_Space(c),
_ => false, _ => false,
} }
@ -737,7 +737,7 @@ impl char {
#[inline] #[inline]
pub fn is_numeric(self) -> bool { pub fn is_numeric(self) -> bool {
match self { match self {
'0'...'9' => true, '0'..='9' => true,
c if c > '\x7f' => general_category::N(c), c if c > '\x7f' => general_category::N(c),
_ => false, _ => false,
} }

View file

@ -121,19 +121,19 @@ macro_rules! radix {
fn digit(x: u8) -> u8 { fn digit(x: u8) -> u8 {
match x { match x {
$($x => $conv,)+ $($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! { Binary, 2, "0b", x @ 0 ..= 1 => b'0' + x }
radix! { Octal, 8, "0o", x @ 0 ... 7 => b'0' + x } radix! { Octal, 8, "0o", x @ 0 ..= 7 => b'0' + x }
radix! { LowerHex, 16, "0x", x @ 0 ... 9 => b'0' + x, radix! { LowerHex, 16, "0x", x @ 0 ..= 9 => b'0' + x,
x @ 10 ... 15 => b'a' + (x - 10) } x @ 10 ..= 15 => b'a' + (x - 10) }
radix! { UpperHex, 16, "0x", x @ 0 ... 9 => b'0' + x, radix! { UpperHex, 16, "0x", x @ 0 ..= 9 => b'0' + x,
x @ 10 ... 15 => b'A' + (x - 10) } x @ 10 ..= 15 => b'A' + (x - 10) }
macro_rules! int_base { macro_rules! int_base {
($Trait:ident for $T:ident as $U:ident -> $Radix:ident) => { ($Trait:ident for $T:ident as $U:ident -> $Radix:ident) => {

View file

@ -1230,7 +1230,7 @@ impl<T> [T] {
/// assert_eq!(s.binary_search(&4), Err(7)); /// assert_eq!(s.binary_search(&4), Err(7));
/// assert_eq!(s.binary_search(&100), Err(13)); /// assert_eq!(s.binary_search(&100), Err(13));
/// let r = s.binary_search(&1); /// 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")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn binary_search(&self, x: &T) -> Result<usize, usize> pub fn binary_search(&self, x: &T) -> Result<usize, usize>
@ -1268,7 +1268,7 @@ impl<T> [T] {
/// assert_eq!(s.binary_search_by(|probe| probe.cmp(&seek)), Err(13)); /// assert_eq!(s.binary_search_by(|probe| probe.cmp(&seek)), Err(13));
/// let seek = 1; /// let seek = 1;
/// let r = s.binary_search_by(|probe| probe.cmp(&seek)); /// 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")] #[stable(feature = "rust1", since = "1.0.0")]
#[inline] #[inline]
@ -1325,7 +1325,7 @@ impl<T> [T] {
/// assert_eq!(s.binary_search_by_key(&4, |&(a,b)| b), Err(7)); /// 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)); /// assert_eq!(s.binary_search_by_key(&100, |&(a,b)| b), Err(13));
/// let r = s.binary_search_by_key(&1, |&(a,b)| b); /// 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")] #[stable(feature = "slice_binary_search_by_key", since = "1.10.0")]
#[inline] #[inline]

View file

@ -101,10 +101,10 @@ impl<'a> Iterator for Utf8LossyChunksIter<'a> {
} }
3 => { 3 => {
match (byte, safe_get(self.source, i)) { match (byte, safe_get(self.source, i)) {
(0xE0, 0xA0 ... 0xBF) => (), (0xE0, 0xA0 ..= 0xBF) => (),
(0xE1 ... 0xEC, 0x80 ... 0xBF) => (), (0xE1 ..= 0xEC, 0x80 ..= 0xBF) => (),
(0xED, 0x80 ... 0x9F) => (), (0xED, 0x80 ..= 0x9F) => (),
(0xEE ... 0xEF, 0x80 ... 0xBF) => (), (0xEE ..= 0xEF, 0x80 ..= 0xBF) => (),
_ => { _ => {
error!(); error!();
} }
@ -117,9 +117,9 @@ impl<'a> Iterator for Utf8LossyChunksIter<'a> {
} }
4 => { 4 => {
match (byte, safe_get(self.source, i)) { match (byte, safe_get(self.source, i)) {
(0xF0, 0x90 ... 0xBF) => (), (0xF0, 0x90 ..= 0xBF) => (),
(0xF1 ... 0xF3, 0x80 ... 0xBF) => (), (0xF1 ..= 0xF3, 0x80 ..= 0xBF) => (),
(0xF4, 0x80 ... 0x8F) => (), (0xF4, 0x80 ..= 0x8F) => (),
_ => { _ => {
error!(); error!();
} }

View file

@ -1484,10 +1484,10 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
}, },
3 => { 3 => {
match (first, next!()) { match (first, next!()) {
(0xE0 , 0xA0 ... 0xBF) | (0xE0 , 0xA0 ..= 0xBF) |
(0xE1 ... 0xEC, 0x80 ... 0xBF) | (0xE1 ..= 0xEC, 0x80 ..= 0xBF) |
(0xED , 0x80 ... 0x9F) | (0xED , 0x80 ..= 0x9F) |
(0xEE ... 0xEF, 0x80 ... 0xBF) => {} (0xEE ..= 0xEF, 0x80 ..= 0xBF) => {}
_ => err!(Some(1)) _ => err!(Some(1))
} }
if next!() & !CONT_MASK != TAG_CONT_U8 { if next!() & !CONT_MASK != TAG_CONT_U8 {
@ -1496,9 +1496,9 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
} }
4 => { 4 => {
match (first, next!()) { match (first, next!()) {
(0xF0 , 0x90 ... 0xBF) | (0xF0 , 0x90 ..= 0xBF) |
(0xF1 ... 0xF3, 0x80 ... 0xBF) | (0xF1 ..= 0xF3, 0x80 ..= 0xBF) |
(0xF4 , 0x80 ... 0x8F) => {} (0xF4 , 0x80 ..= 0x8F) => {}
_ => err!(Some(1)) _ => err!(Some(1))
} }
if next!() & !CONT_MASK != TAG_CONT_U8 { if next!() & !CONT_MASK != TAG_CONT_U8 {

View file

@ -60,8 +60,8 @@ fn test_binary_search() {
assert_eq!(b.binary_search(&0), Err(0)); assert_eq!(b.binary_search(&0), Err(0));
assert_eq!(b.binary_search(&1), Ok(0)); assert_eq!(b.binary_search(&1), Ok(0));
assert_eq!(b.binary_search(&2), Err(1)); 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(&4), Err(4));
assert_eq!(b.binary_search(&5), Err(4)); assert_eq!(b.binary_search(&5), Err(4));
assert_eq!(b.binary_search(&6), Err(4)); assert_eq!(b.binary_search(&6), Err(4));

View file

@ -1753,9 +1753,9 @@ impl<S: Semantics> IeeeFloat<S> {
} else { } else {
loss = Some(match hex_value { loss = Some(match hex_value {
0 => Loss::ExactlyZero, 0 => Loss::ExactlyZero,
1...7 => Loss::LessThanHalf, 1..=7 => Loss::LessThanHalf,
8 => Loss::ExactlyHalf, 8 => Loss::ExactlyHalf,
9...15 => Loss::MoreThanHalf, 9..=15 => Loss::MoreThanHalf,
_ => unreachable!(), _ => unreachable!(),
}); });
} }

View file

@ -424,7 +424,7 @@ pub fn sanitize(result: &mut String, s: &str) -> bool {
'-' | ':' => result.push('.'), '-' | ':' => result.push('.'),
// These are legal symbols // These are legal symbols
'a'...'z' | 'A'...'Z' | '0'...'9' | '_' | '.' | '$' => result.push(c), 'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '.' | '$' => result.push(c),
_ => { _ => {
result.push('$'); result.push('$');

View file

@ -306,9 +306,9 @@ For example:
```compile_fail ```compile_fail
match 5u32 { match 5u32 {
// This range is ok, albeit pointless. // This range is ok, albeit pointless.
1 ... 1 => {} 1 ..= 1 => {}
// This range is empty, and the compiler can tell. // This range is empty, and the compiler can tell.
1000 ... 5 => {} 1000 ..= 5 => {}
} }
``` ```
"##, "##,

View file

@ -481,7 +481,7 @@ fn check_exhaustive<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
let joined_patterns = match witnesses.len() { let joined_patterns = match witnesses.len() {
0 => bug!(), 0 => bug!(),
1 => format!("`{}`", witnesses[0]), 1 => format!("`{}`", witnesses[0]),
2...LIMIT => { 2..=LIMIT => {
let (tail, head) = witnesses.split_last().unwrap(); let (tail, head) = witnesses.split_last().unwrap();
let head: Vec<_> = head.iter().map(|w| w.to_string()).collect(); let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
format!("`{}` and `{}`", head.join("`, `"), tail) format!("`{}` and `{}`", head.join("`, `"), tail)

View file

@ -139,11 +139,11 @@ impl Reg {
RegKind::Integer => { RegKind::Integer => {
match self.size.bits() { match self.size.bits() {
1 => dl.i1_align, 1 => dl.i1_align,
2...8 => dl.i8_align, 2..=8 => dl.i8_align,
9...16 => dl.i16_align, 9..=16 => dl.i16_align,
17...32 => dl.i32_align, 17..=32 => dl.i32_align,
33...64 => dl.i64_align, 33..=64 => dl.i64_align,
65...128 => dl.i128_align, 65..=128 => dl.i128_align,
_ => panic!("unsupported integer: {:?}", self) _ => panic!("unsupported integer: {:?}", self)
} }
} }

View file

@ -441,10 +441,10 @@ impl Integer {
/// Find the smallest Integer type which can represent the signed value. /// Find the smallest Integer type which can represent the signed value.
pub fn fit_signed(x: i128) -> Integer { pub fn fit_signed(x: i128) -> Integer {
match x { match x {
-0x0000_0000_0000_0080...0x0000_0000_0000_007f => I8, -0x0000_0000_0000_0080..=0x0000_0000_0000_007f => I8,
-0x0000_0000_0000_8000...0x0000_0000_0000_7fff => I16, -0x0000_0000_0000_8000..=0x0000_0000_0000_7fff => I16,
-0x0000_0000_8000_0000...0x0000_0000_7fff_ffff => I32, -0x0000_0000_8000_0000..=0x0000_0000_7fff_ffff => I32,
-0x8000_0000_0000_0000...0x7fff_ffff_ffff_ffff => I64, -0x8000_0000_0000_0000..=0x7fff_ffff_ffff_ffff => I64,
_ => I128 _ => I128
} }
} }
@ -452,10 +452,10 @@ impl Integer {
/// Find the smallest Integer type which can represent the unsigned value. /// Find the smallest Integer type which can represent the unsigned value.
pub fn fit_unsigned(x: u128) -> Integer { pub fn fit_unsigned(x: u128) -> Integer {
match x { match x {
0...0x0000_0000_0000_00ff => I8, 0..=0x0000_0000_0000_00ff => I8,
0...0x0000_0000_0000_ffff => I16, 0..=0x0000_0000_0000_ffff => I16,
0...0x0000_0000_ffff_ffff => I32, 0..=0x0000_0000_ffff_ffff => I32,
0...0xffff_ffff_ffff_ffff => I64, 0..=0xffff_ffff_ffff_ffff => I64,
_ => I128, _ => I128,
} }
} }

View file

@ -207,7 +207,7 @@ let string = "salutations !";
// The ordering relation for strings can't be evaluated at compile time, // The ordering relation for strings can't be evaluated at compile time,
// so this doesn't work: // so this doesn't work:
match string { match string {
"hello" ... "world" => {} "hello" ..= "world" => {}
_ => {} _ => {}
} }
@ -2146,7 +2146,7 @@ fn main() -> i32 { 0 }
let x = 1u8; let x = 1u8;
match x { match x {
0u8...3i8 => (), 0u8..=3i8 => (),
// error: mismatched types in range: expected u8, found i8 // error: mismatched types in range: expected u8, found i8
_ => () _ => ()
} }
@ -2189,7 +2189,7 @@ as the type you're matching on. Example:
let x = 1u8; let x = 1u8;
match x { match x {
0u8...3u8 => (), // ok! 0u8..=3u8 => (), // ok!
_ => () _ => ()
} }
``` ```

View file

@ -125,9 +125,9 @@ impl FromHex for str {
buf <<= 4; buf <<= 4;
match byte { match byte {
b'A'...b'F' => buf |= byte - b'A' + 10, b'A'..=b'F' => buf |= byte - b'A' + 10,
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'0'..=b'9' => buf |= byte - b'0',
b' '|b'\r'|b'\n'|b'\t' => { b' '|b'\r'|b'\n'|b'\t' => {
buf >>= 4; buf >>= 4;
continue continue

View file

@ -1557,14 +1557,14 @@ impl<T: Iterator<Item=char>> Parser<T> {
self.bump(); self.bump();
// A leading '0' must be the only digit before the decimal point. // 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) return self.error(InvalidNumber)
} }
}, },
'1' ... '9' => { '1' ..= '9' => {
while !self.eof() { while !self.eof() {
match self.ch_or_null() { match self.ch_or_null() {
c @ '0' ... '9' => { c @ '0' ..= '9' => {
accum = accum.wrapping_mul(10); accum = accum.wrapping_mul(10);
accum = accum.wrapping_add((c as u64) - ('0' as u64)); accum = accum.wrapping_add((c as u64) - ('0' as u64));
@ -1588,14 +1588,14 @@ impl<T: Iterator<Item=char>> Parser<T> {
// Make sure a digit follows the decimal place. // Make sure a digit follows the decimal place.
match self.ch_or_null() { match self.ch_or_null() {
'0' ... '9' => (), '0' ..= '9' => (),
_ => return self.error(InvalidNumber) _ => return self.error(InvalidNumber)
} }
let mut dec = 1.0; let mut dec = 1.0;
while !self.eof() { while !self.eof() {
match self.ch_or_null() { match self.ch_or_null() {
c @ '0' ... '9' => { c @ '0' ..= '9' => {
dec /= 10.0; dec /= 10.0;
res += (((c as isize) - ('0' as isize)) as f64) * dec; res += (((c as isize) - ('0' as isize)) as f64) * dec;
self.bump(); self.bump();
@ -1622,12 +1622,12 @@ impl<T: Iterator<Item=char>> Parser<T> {
// Make sure a digit follows the exponent place. // Make sure a digit follows the exponent place.
match self.ch_or_null() { match self.ch_or_null() {
'0' ... '9' => (), '0' ..= '9' => (),
_ => return self.error(InvalidNumber) _ => return self.error(InvalidNumber)
} }
while !self.eof() { while !self.eof() {
match self.ch_or_null() { match self.ch_or_null() {
c @ '0' ... '9' => { c @ '0' ..= '9' => {
exp *= 10; exp *= 10;
exp += (c as usize) - ('0' as usize); exp += (c as usize) - ('0' as usize);
@ -1653,7 +1653,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
while i < 4 && !self.eof() { while i < 4 && !self.eof() {
self.bump(); self.bump();
n = match self.ch_or_null() { 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, 'a' | 'A' => n * 16 + 10,
'b' | 'B' => n * 16 + 11, 'b' | 'B' => n * 16 + 11,
'c' | 'C' => n * 16 + 12, 'c' | 'C' => n * 16 + 12,
@ -1695,13 +1695,13 @@ impl<T: Iterator<Item=char>> Parser<T> {
'r' => res.push('\r'), 'r' => res.push('\r'),
't' => res.push('\t'), 't' => res.push('\t'),
'u' => match self.decode_hex_escape()? { 'u' => match self.decode_hex_escape()? {
0xDC00 ... 0xDFFF => { 0xDC00 ..= 0xDFFF => {
return self.error(LoneLeadingSurrogateInHexEscape) return self.error(LoneLeadingSurrogateInHexEscape)
} }
// Non-BMP characters are encoded as a sequence of // Non-BMP characters are encoded as a sequence of
// two hex escapes, representing UTF-16 surrogates. // two hex escapes, representing UTF-16 surrogates.
n1 @ 0xD800 ... 0xDBFF => { n1 @ 0xD800 ..= 0xDBFF => {
match (self.next_char(), self.next_char()) { match (self.next_char(), self.next_char()) {
(Some('\\'), Some('u')) => (), (Some('\\'), Some('u')) => (),
_ => return self.error(UnexpectedEndOfHexEscape), _ => return self.error(UnexpectedEndOfHexEscape),
@ -1928,7 +1928,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
'n' => { self.parse_ident("ull", NullValue) } 'n' => { self.parse_ident("ull", NullValue) }
't' => { self.parse_ident("rue", BooleanValue(true)) } 't' => { self.parse_ident("rue", BooleanValue(true)) }
'f' => { self.parse_ident("alse", BooleanValue(false)) } 'f' => { self.parse_ident("alse", BooleanValue(false)) }
'0' ... '9' | '-' => self.parse_number(), '0' ..= '9' | '-' => self.parse_number(),
'"' => match self.parse_str() { '"' => match self.parse_str() {
Ok(s) => StringValue(s), Ok(s) => StringValue(s),
Err(e) => Error(e), Err(e) => Error(e),

View file

@ -263,7 +263,7 @@ pub fn demangle(writer: &mut Write, mut s: &str, format: PrintFormat) -> io::Res
let candidate = &s[i + llvm.len()..]; let candidate = &s[i + llvm.len()..];
let all_hex = candidate.chars().all(|c| { let all_hex = candidate.chars().all(|c| {
match c { match c {
'A' ... 'F' | '0' ... '9' => true, 'A' ..= 'F' | '0' ..= '9' => true,
_ => false, _ => false,
} }
}); });

View file

@ -76,7 +76,7 @@ impl CodePoint {
#[inline] #[inline]
pub fn from_u32(value: u32) -> Option<CodePoint> { pub fn from_u32(value: u32) -> Option<CodePoint> {
match value { match value {
0 ... 0x10FFFF => Some(CodePoint { value: value }), 0 ..= 0x10FFFF => Some(CodePoint { value: value }),
_ => None _ => None
} }
} }
@ -101,7 +101,7 @@ impl CodePoint {
#[inline] #[inline]
pub fn to_char(&self) -> Option<char> { pub fn to_char(&self) -> Option<char> {
match self.value { match self.value {
0xD800 ... 0xDFFF => None, 0xD800 ..= 0xDFFF => None,
_ => Some(unsafe { char::from_u32_unchecked(self.value) }) _ => Some(unsafe { char::from_u32_unchecked(self.value) })
} }
} }
@ -305,7 +305,7 @@ impl Wtf8Buf {
/// like concatenating ill-formed UTF-16 strings effectively would. /// like concatenating ill-formed UTF-16 strings effectively would.
#[inline] #[inline]
pub fn push(&mut self, code_point: CodePoint) { 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() { if let Some(lead) = (&*self).final_lead_surrogate() {
let len_without_lead_surrogate = self.len() - 3; let len_without_lead_surrogate = self.len() - 3;
self.bytes.truncate(len_without_lead_surrogate); self.bytes.truncate(len_without_lead_surrogate);
@ -525,7 +525,7 @@ impl Wtf8 {
#[inline] #[inline]
pub fn ascii_byte_at(&self, position: usize) -> u8 { pub fn ascii_byte_at(&self, position: usize) -> u8 {
match self.bytes[position] { match self.bytes[position] {
ascii_byte @ 0x00 ... 0x7F => ascii_byte, ascii_byte @ 0x00 ..= 0x7F => ascii_byte,
_ => 0xFF _ => 0xFF
} }
} }
@ -630,7 +630,7 @@ impl Wtf8 {
return None return None
} }
match &self.bytes[(len - 3)..] { 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 _ => None
} }
} }
@ -642,7 +642,7 @@ impl Wtf8 {
return None return None
} }
match &self.bytes[..3] { 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 _ => None
} }
} }

View file

@ -843,11 +843,11 @@ pub struct Local {
/// An arm of a 'match'. /// An arm of a 'match'.
/// ///
/// E.g. `0...10 => { println!("match!") }` as in /// E.g. `0..=10 => { println!("match!") }` as in
/// ///
/// ``` /// ```
/// match 123 { /// match 123 {
/// 0...10 => { println!("match!") }, /// 0..=10 => { println!("match!") },
/// _ => { println!("no match!") }, /// _ => { println!("no match!") },
/// } /// }
/// ``` /// ```

View file

@ -266,7 +266,7 @@ impl<'a> StringReader<'a> {
/// Pushes a character to a message string for error reporting /// Pushes a character to a message string for error reporting
fn push_escaped_char_for_msg(m: &mut String, c: char) { fn push_escaped_char_for_msg(m: &mut String, c: char) {
match c { match c {
'\u{20}'...'\u{7e}' => { '\u{20}'..='\u{7e}' => {
// Don't escape \, ' or " for user-facing messages // Don't escape \, ' or " for user-facing messages
m.push(c); m.push(c);
} }
@ -779,7 +779,7 @@ impl<'a> StringReader<'a> {
base = 16; base = 16;
num_digits = self.scan_digits(16, 16); num_digits = self.scan_digits(16, 16);
} }
'0'...'9' | '_' | '.' | 'e' | 'E' => { '0'..='9' | '_' | '.' | 'e' | 'E' => {
num_digits = self.scan_digits(10, 10) + 1; num_digits = self.scan_digits(10, 10) + 1;
} }
_ => { _ => {

View file

@ -374,7 +374,7 @@ pub mod printf {
if let Start = state { if let Start = state {
match c { match c {
'1'...'9' => { '1'..='9' => {
let end = at_next_cp_while(next, is_digit); let end = at_next_cp_while(next, is_digit);
match end.next_cp() { match end.next_cp() {
// Yes, this *is* the parameter. // Yes, this *is* the parameter.
@ -416,7 +416,7 @@ pub mod printf {
state = WidthArg; state = WidthArg;
move_to!(next); move_to!(next);
}, },
'1' ... '9' => { '1' ..= '9' => {
let end = at_next_cp_while(next, is_digit); let end = at_next_cp_while(next, is_digit);
state = Prec; state = Prec;
width = Some(Num::from_str(at.slice_between(end).unwrap(), None)); 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); let end = at_next_cp_while(next, is_digit);
state = Length; state = Length;
precision = Some(Num::from_str(at.slice_between(end).unwrap(), None)); precision = Some(Num::from_str(at.slice_between(end).unwrap(), None));
@ -570,7 +570,7 @@ pub mod printf {
fn is_digit(c: char) -> bool { fn is_digit(c: char) -> bool {
match c { match c {
'0' ... '9' => true, '0' ..= '9' => true,
_ => false _ => false
} }
} }
@ -799,7 +799,7 @@ pub mod shell {
let start = s.find('$')?; let start = s.find('$')?;
match s[start+1..].chars().next()? { match s[start+1..].chars().next()? {
'$' => return Some((Substitution::Escape, &s[start+2..])), '$' => return Some((Substitution::Escape, &s[start+2..])),
c @ '0' ... '9' => { c @ '0' ..= '9' => {
let n = (c as u8) - b'0'; let n = (c as u8) - b'0';
return Some((Substitution::Ordinal(n), &s[start+2..])); return Some((Substitution::Ordinal(n), &s[start+2..]));
}, },
@ -836,14 +836,14 @@ pub mod shell {
fn is_ident_head(c: char) -> bool { fn is_ident_head(c: char) -> bool {
match c { match c {
'a' ... 'z' | 'A' ... 'Z' | '_' => true, 'a' ..= 'z' | 'A' ..= 'Z' | '_' => true,
_ => false _ => false
} }
} }
fn is_ident_tail(c: char) -> bool { fn is_ident_tail(c: char) -> bool {
match c { match c {
'0' ... '9' => true, '0' ..= '9' => true,
c => is_ident_head(c) c => is_ident_head(c)
} }
} }

View file

@ -818,8 +818,8 @@ impl Encodable for FileMap {
}; };
let bytes_per_diff: u8 = match max_line_length { let bytes_per_diff: u8 = match max_line_length {
0 ... 0xFF => 1, 0 ..= 0xFF => 1,
0x100 ... 0xFFFF => 2, 0x100 ..= 0xFFFF => 2,
_ => 4 _ => 4
}; };

View file

@ -215,7 +215,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec<
return Err("stack is empty".to_string()); return Err("stack is empty".to_string());
} }
} }
':' | '#' | ' ' | '.' | '0'...'9' => { ':' | '#' | ' ' | '.' | '0'..='9' => {
let mut flags = Flags::new(); let mut flags = Flags::new();
let mut fstate = FormatStateFlags; let mut fstate = FormatStateFlags;
match cur { match cur {
@ -223,7 +223,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec<
'#' => flags.alternate = true, '#' => flags.alternate = true,
' ' => flags.space = true, ' ' => flags.space = true,
'.' => fstate = FormatStatePrecision, '.' => fstate = FormatStatePrecision,
'0'...'9' => { '0'..='9' => {
flags.width = cur as usize - '0' as usize; flags.width = cur as usize - '0' as usize;
fstate = FormatStateWidth; fstate = FormatStateWidth;
} }
@ -337,14 +337,14 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec<
(FormatStateFlags, ' ') => { (FormatStateFlags, ' ') => {
flags.space = true; flags.space = true;
} }
(FormatStateFlags, '0'...'9') => { (FormatStateFlags, '0'..='9') => {
flags.width = cur as usize - '0' as usize; flags.width = cur as usize - '0' as usize;
*fstate = FormatStateWidth; *fstate = FormatStateWidth;
} }
(FormatStateFlags, '.') => { (FormatStateFlags, '.') => {
*fstate = FormatStatePrecision; *fstate = FormatStatePrecision;
} }
(FormatStateWidth, '0'...'9') => { (FormatStateWidth, '0'..='9') => {
let old = flags.width; let old = flags.width;
flags.width = flags.width * 10 + (cur as usize - '0' as usize); flags.width = flags.width * 10 + (cur as usize - '0' as usize);
if flags.width < old { if flags.width < old {
@ -354,7 +354,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec<
(FormatStateWidth, '.') => { (FormatStateWidth, '.') => {
*fstate = FormatStatePrecision; *fstate = FormatStatePrecision;
} }
(FormatStatePrecision, '0'...'9') => { (FormatStatePrecision, '0'..='9') => {
let old = flags.precision; let old = flags.precision;
flags.precision = flags.precision * 10 + (cur as usize - '0' as usize); flags.precision = flags.precision * 10 + (cur as usize - '0' as usize);
if flags.precision < old { if flags.precision < old {

View file

@ -14,7 +14,7 @@ fn main() {
let _: <<A>::B>::C; //~ ERROR cannot find type `A` in this scope let _: <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
let _ = <<A>::B>::C; //~ ERROR cannot find type `A` in this scope let _ = <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
let <<A>::B>::C; //~ ERROR cannot find type `A` in this scope let <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
let 0 ... <<A>::B>::C; //~ ERROR cannot find type `A` in this scope let 0 ..= <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
//~^ ERROR only char and numeric types are allowed in range patterns //~^ ERROR only char and numeric types are allowed in range patterns
<<A>::B>::C; //~ ERROR cannot find type `A` in this scope <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
} }

View file

@ -13,7 +13,7 @@ fn main() {
let index = 6; let index = 6;
match i { match i {
0...index => println!("winner"), 0..=index => println!("winner"),
//~^ ERROR runtime values cannot be referenced in patterns //~^ ERROR runtime values cannot be referenced in patterns
_ => println!("hello"), _ => println!("hello"),
} }

View file

@ -27,7 +27,7 @@ fn main() {
//~| WARNING hard error //~| WARNING hard error
//~| ERROR floating-point types cannot be used in patterns //~| ERROR floating-point types cannot be used in patterns
//~| WARNING hard error //~| 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 //~| WARNING hard error
//~| ERROR floating-point types cannot be used in patterns //~| ERROR floating-point types cannot be used in patterns
//~| WARNING hard error //~| WARNING hard error

View file

@ -12,7 +12,7 @@
fn main() { fn main() {
match 5 { match 5 {
6 ... 1 => { } 6 ..= 1 => { }
_ => { } _ => { }
}; };
//~^^^ ERROR lower range bound must be less than or equal to upper //~^^^ 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 //~^^^ ERROR lower range bound must be less than upper
match 5u64 { match 5u64 {
0xFFFF_FFFF_FFFF_FFFF ... 1 => { } 0xFFFF_FFFF_FFFF_FFFF ..= 1 => { }
_ => { } _ => { }
}; };
//~^^^ ERROR lower range bound must be less than or equal to upper //~^^^ ERROR lower range bound must be less than or equal to upper

View file

@ -10,21 +10,21 @@
fn main() { fn main() {
match "wow" { match "wow" {
"bar" ... "foo" => { } "bar" ..= "foo" => { }
}; };
//~^^ ERROR only char and numeric types are allowed in range //~^^ ERROR only char and numeric types are allowed in range
//~| start type: &'static str //~| start type: &'static str
//~| end type: &'static str //~| end type: &'static str
match "wow" { match "wow" {
10 ... "what" => () 10 ..= "what" => ()
}; };
//~^^ ERROR only char and numeric types are allowed in range //~^^ ERROR only char and numeric types are allowed in range
//~| start type: {integer} //~| start type: {integer}
//~| end type: &'static str //~| end type: &'static str
match 5 { match 5 {
'c' ... 100 => { } 'c' ..= 100 => { }
_ => { } _ => { }
}; };
//~^^^ ERROR mismatched types //~^^^ ERROR mismatched types

View file

@ -11,7 +11,7 @@
fn main() { fn main() {
let x = 0; let x = 0;
match 1 { match 1 {
0 ... x => {} 0 ..= x => {}
//~^ ERROR runtime values cannot be referenced in patterns //~^ ERROR runtime values cannot be referenced in patterns
}; };
} }

View file

@ -17,7 +17,7 @@ macro_rules! enum_number {
fn foo(value: i32) -> Option<$name> { fn foo(value: i32) -> Option<$name> {
match value { match value {
$( $value => Some($name::$variant), )* // PatKind::Lit $( $value => Some($name::$variant), )* // PatKind::Lit
$( $value ... 42 => Some($name::$variant), )* // PatKind::Range $( $value ..= 42 => Some($name::$variant), )* // PatKind::Range
_ => None _ => None
} }
} }
@ -32,4 +32,3 @@ enum_number!(Change {
}); });
fn main() {} fn main() {}

View file

@ -29,6 +29,6 @@ fn main() {
match 10 { match 10 {
<S as Tr>::A::f::<u8> => {} <S as Tr>::A::f::<u8> => {}
//~^ ERROR expected unit struct/variant or constant, found method `<<S as Tr>::A>::f<u8>` //~^ ERROR expected unit struct/variant or constant, found method `<<S as Tr>::A>::f<u8>`
0 ... <S as Tr>::A::f::<u8> => {} //~ ERROR only char and numeric types are allowed in range 0 ..= <S as Tr>::A::f::<u8> => {} //~ ERROR only char and numeric types are allowed in range
} }
} }

View file

@ -9,10 +9,10 @@
// except according to those terms. // except according to those terms.
fn func((1, (Some(1), 2...3)): (isize, (Option<isize>, isize))) { } fn func((1, (Some(1), 2..=3)): (isize, (Option<isize>, isize))) { }
//~^ ERROR refutable pattern in function argument: `(_, _)` not covered //~^ ERROR refutable pattern in function argument: `(_, _)` not covered
fn main() { 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 //~^ ERROR refutable pattern in local binding: `(_, _)` not covered
} }

View file

@ -286,16 +286,16 @@ fn run() {
// would require parens in patterns to allow disambiguation... // would require parens in patterns to allow disambiguation...
reject_expr_parse("match 0 { reject_expr_parse("match 0 {
0...#[attr] 10 => () 0..=#[attr] 10 => ()
}"); }");
reject_expr_parse("match 0 { reject_expr_parse("match 0 {
0...#[attr] -10 => () 0..=#[attr] -10 => ()
}"); }");
reject_expr_parse("match 0 { reject_expr_parse("match 0 {
0...-#[attr] 10 => () 0..=-#[attr] 10 => ()
}"); }");
reject_expr_parse("match 0 { reject_expr_parse("match 0 {
0...#[attr] FOO => () 0..=#[attr] FOO => ()
}"); }");
// make sure we don't catch this bug again... // make sure we don't catch this bug again...

View file

@ -36,7 +36,7 @@ pub fn main() {
} }
match 100 { match 100 {
b'a' ... b'z' => {}, b'a' ..= b'z' => {},
_ => panic!() _ => panic!()
} }

View file

@ -12,21 +12,21 @@
pub fn main() { pub fn main() {
let x = 2; let x = 2;
let x_message = match x { let x_message = match x {
0 ... 1 => { "not many".to_string() } 0 ..= 1 => { "not many".to_string() }
_ => { "lots".to_string() } _ => { "lots".to_string() }
}; };
assert_eq!(x_message, "lots".to_string()); assert_eq!(x_message, "lots".to_string());
let y = 2; let y = 2;
let y_message = match y { let y_message = match y {
0 ... 1 => { "not many".to_string() } 0 ..= 1 => { "not many".to_string() }
_ => { "lots".to_string() } _ => { "lots".to_string() }
}; };
assert_eq!(y_message, "lots".to_string()); assert_eq!(y_message, "lots".to_string());
let z = 1u64; let z = 1u64;
let z_message = match z { let z_message = match z {
0 ... 1 => { "not many".to_string() } 0 ..= 1 => { "not many".to_string() }
_ => { "lots".to_string() } _ => { "lots".to_string() }
}; };
assert_eq!(z_message, "not many".to_string()); assert_eq!(z_message, "not many".to_string());

View file

@ -16,7 +16,7 @@ pub fn main() {
assert_eq!(3, match (x, y) { assert_eq!(3, match (x, y) {
(1, 1) => 1, (1, 1) => 1,
(2, 2) => 2, (2, 2) => 2,
(1...2, 2) => 3, (1..=2, 2) => 3,
_ => 4, _ => 4,
}); });
@ -24,7 +24,7 @@ pub fn main() {
assert_eq!(3, match ((x, y),) { assert_eq!(3, match ((x, y),) {
((1, 1),) => 1, ((1, 1),) => 1,
((2, 2),) => 2, ((2, 2),) => 2,
((1...2, 2),) => 3, ((1..=2, 2),) => 3,
_ => 4, _ => 4,
}); });
} }

View file

@ -30,7 +30,7 @@ pub fn main() {
fn lit_shadow_range() { fn lit_shadow_range() {
assert_eq!(2, match 1 { assert_eq!(2, match 1 {
1 if false => 1, 1 if false => 1,
1...2 => 2, 1..=2 => 2,
_ => 3 _ => 3
}); });
@ -38,34 +38,34 @@ fn lit_shadow_range() {
assert_eq!(2, match x+1 { assert_eq!(2, match x+1 {
0 => 0, 0 => 0,
1 if false => 1, 1 if false => 1,
1...2 => 2, 1..=2 => 2,
_ => 3 _ => 3
}); });
assert_eq!(2, match val() { assert_eq!(2, match val() {
1 if false => 1, 1 if false => 1,
1...2 => 2, 1..=2 => 2,
_ => 3 _ => 3
}); });
assert_eq!(2, match CONST { assert_eq!(2, match CONST {
0 => 0, 0 => 0,
1 if false => 1, 1 if false => 1,
1...2 => 2, 1..=2 => 2,
_ => 3 _ => 3
}); });
// value is out of the range of second arm, should match wildcard pattern // value is out of the range of second arm, should match wildcard pattern
assert_eq!(3, match 3 { assert_eq!(3, match 3 {
1 if false => 1, 1 if false => 1,
1...2 => 2, 1..=2 => 2,
_ => 3 _ => 3
}); });
} }
fn range_shadow_lit() { fn range_shadow_lit() {
assert_eq!(2, match 1 { assert_eq!(2, match 1 {
1...2 if false => 1, 1..=2 if false => 1,
1 => 2, 1 => 2,
_ => 3 _ => 3
}); });
@ -73,27 +73,27 @@ fn range_shadow_lit() {
let x = 0; let x = 0;
assert_eq!(2, match x+1 { assert_eq!(2, match x+1 {
0 => 0, 0 => 0,
1...2 if false => 1, 1..=2 if false => 1,
1 => 2, 1 => 2,
_ => 3 _ => 3
}); });
assert_eq!(2, match val() { assert_eq!(2, match val() {
1...2 if false => 1, 1..=2 if false => 1,
1 => 2, 1 => 2,
_ => 3 _ => 3
}); });
assert_eq!(2, match CONST { assert_eq!(2, match CONST {
0 => 0, 0 => 0,
1...2 if false => 1, 1..=2 if false => 1,
1 => 2, 1 => 2,
_ => 3 _ => 3
}); });
// ditto // ditto
assert_eq!(3, match 3 { assert_eq!(3, match 3 {
1...2 if false => 1, 1..=2 if false => 1,
1 => 2, 1 => 2,
_ => 3 _ => 3
}); });
@ -101,36 +101,36 @@ fn range_shadow_lit() {
fn range_shadow_range() { fn range_shadow_range() {
assert_eq!(2, match 1 { assert_eq!(2, match 1 {
0...2 if false => 1, 0..=2 if false => 1,
1...3 => 2, 1..=3 => 2,
_ => 3, _ => 3,
}); });
let x = 0; let x = 0;
assert_eq!(2, match x+1 { assert_eq!(2, match x+1 {
100 => 0, 100 => 0,
0...2 if false => 1, 0..=2 if false => 1,
1...3 => 2, 1..=3 => 2,
_ => 3, _ => 3,
}); });
assert_eq!(2, match val() { assert_eq!(2, match val() {
0...2 if false => 1, 0..=2 if false => 1,
1...3 => 2, 1..=3 => 2,
_ => 3, _ => 3,
}); });
assert_eq!(2, match CONST { assert_eq!(2, match CONST {
100 => 0, 100 => 0,
0...2 if false => 1, 0..=2 if false => 1,
1...3 => 2, 1..=3 => 2,
_ => 3, _ => 3,
}); });
// ditto // ditto
assert_eq!(3, match 5 { assert_eq!(3, match 5 {
0...2 if false => 1, 0..=2 if false => 1,
1...3 => 2, 1..=3 => 2,
_ => 3, _ => 3,
}); });
} }
@ -138,7 +138,7 @@ fn range_shadow_range() {
fn multi_pats_shadow_lit() { fn multi_pats_shadow_lit() {
assert_eq!(2, match 1 { assert_eq!(2, match 1 {
100 => 0, 100 => 0,
0 | 1...10 if false => 1, 0 | 1..=10 if false => 1,
1 => 2, 1 => 2,
_ => 3, _ => 3,
}); });
@ -147,8 +147,8 @@ fn multi_pats_shadow_lit() {
fn multi_pats_shadow_range() { fn multi_pats_shadow_range() {
assert_eq!(2, match 1 { assert_eq!(2, match 1 {
100 => 0, 100 => 0,
0 | 1...10 if false => 1, 0 | 1..=10 if false => 1,
1...3 => 2, 1..=3 => 2,
_ => 3, _ => 3,
}); });
} }
@ -157,7 +157,7 @@ fn lit_shadow_multi_pats() {
assert_eq!(2, match 1 { assert_eq!(2, match 1 {
100 => 0, 100 => 0,
1 if false => 1, 1 if false => 1,
0 | 1...10 => 2, 0 | 1..=10 => 2,
_ => 3, _ => 3,
}); });
} }
@ -165,8 +165,8 @@ fn lit_shadow_multi_pats() {
fn range_shadow_multi_pats() { fn range_shadow_multi_pats() {
assert_eq!(2, match 1 { assert_eq!(2, match 1 {
100 => 0, 100 => 0,
1...3 if false => 1, 1..=3 if false => 1,
0 | 1...10 => 2, 0 | 1..=10 => 2,
_ => 3, _ => 3,
}); });
} }

View file

@ -19,14 +19,14 @@ enum Foo {
fn main() { fn main() {
let r = match (Foo::FooNullary, 'a') { let r = match (Foo::FooNullary, 'a') {
(Foo::FooUint(..), 'a'...'z') => 1, (Foo::FooUint(..), 'a'..='z') => 1,
(Foo::FooNullary, 'x') => 2, (Foo::FooNullary, 'x') => 2,
_ => 0 _ => 0
}; };
assert_eq!(r, 0); assert_eq!(r, 0);
let r = match (Foo::FooUint(0), 'a') { let r = match (Foo::FooUint(0), 'a') {
(Foo::FooUint(1), 'a'...'z') => 1, (Foo::FooUint(1), 'a'..='z') => 1,
(Foo::FooUint(..), 'x') => 2, (Foo::FooUint(..), 'x') => 2,
(Foo::FooNullary, 'a') => 3, (Foo::FooNullary, 'a') => 3,
_ => 0 _ => 0
@ -34,7 +34,7 @@ fn main() {
assert_eq!(r, 0); assert_eq!(r, 0);
let r = match ('a', Foo::FooUint(0)) { let r = match ('a', Foo::FooUint(0)) {
('a'...'z', Foo::FooUint(1)) => 1, ('a'..='z', Foo::FooUint(1)) => 1,
('x', Foo::FooUint(..)) => 2, ('x', Foo::FooUint(..)) => 2,
('a', Foo::FooNullary) => 3, ('a', Foo::FooNullary) => 3,
_ => 0 _ => 0
@ -42,15 +42,15 @@ fn main() {
assert_eq!(r, 0); assert_eq!(r, 0);
let r = match ('a', 'a') { let r = match ('a', 'a') {
('a'...'z', 'b') => 1, ('a'..='z', 'b') => 1,
('x', 'a'...'z') => 2, ('x', 'a'..='z') => 2,
_ => 0 _ => 0
}; };
assert_eq!(r, 0); assert_eq!(r, 0);
let r = match ('a', 'a') { let r = match ('a', 'a') {
('a'...'z', 'b') => 1, ('a'..='z', 'b') => 1,
('x', 'a'...'z') => 2, ('x', 'a'..='z') => 2,
('a', 'a') => 3, ('a', 'a') => 3,
_ => 0 _ => 0
}; };

View file

@ -11,7 +11,7 @@
// Regression test for #18060: match arms were matching in the wrong order. // Regression test for #18060: match arms were matching in the wrong order.
fn main() { 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) { (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, 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, 7) { (0, 2..=5) => 1, (1, 7) => 2, (_, 2..=5) => 3, (_, _) => 4 });
} }

View file

@ -15,7 +15,7 @@ const HIGH_RANGE: char = '9';
fn main() { fn main() {
match '5' { match '5' {
LOW_RANGE...HIGH_RANGE => (), LOW_RANGE..=HIGH_RANGE => (),
_ => () _ => ()
}; };
} }

View file

@ -14,9 +14,9 @@ use m::{START, END};
fn main() { fn main() {
match 42 { match 42 {
m::START...m::END => {}, m::START..=m::END => {},
0...m::END => {}, 0..=m::END => {},
m::START...59 => {}, m::START..=59 => {},
_ => {}, _ => {},
} }
} }

View file

@ -12,9 +12,9 @@ fn main() {
let x = 'a'; let x = 'a';
let y = match x { let y = match x {
'a'...'b' if false => "one", 'a'..='b' if false => "one",
'a' => "two", 'a' => "two",
'a'...'b' => "three", 'a'..='b' => "three",
_ => panic!("what?"), _ => panic!("what?"),
}; };

View file

@ -12,7 +12,7 @@ fn main () {
let x = 4; let x = 4;
match x { match x {
ref r if *r < 0 => println!("got negative num {} < 0", r), 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"), _ => println!("no"),
} }
} }

View file

@ -14,7 +14,7 @@ pub fn main() {
const FOO: f64 = 10.0; const FOO: f64 = 10.0;
match 0.0 { match 0.0 {
0.0 ... FOO => (), 0.0 ..= FOO => (),
_ => () _ => ()
} }
} }

View file

@ -41,18 +41,18 @@ macro_rules! mtester_dbg {
} }
macro_rules! catch_range { macro_rules! catch_range {
($s:literal ... $e:literal) => { ($s:literal ..= $e:literal) => {
&format!("macro caught literal: {} ... {}", $s, $e) &format!("macro caught literal: {} ..= {}", $s, $e)
}; };
(($s:expr) ... ($e:expr)) => { // Must use ')' before '...' (($s:expr) ..= ($e:expr)) => { // Must use ')' before '..='
&format!("macro caught expr: {} ... {}", $s, $e) &format!("macro caught expr: {} ..= {}", $s, $e)
}; };
} }
macro_rules! pat_match { macro_rules! pat_match {
($s:literal ... $e:literal) => { ($s:literal ..= $e:literal) => {
match 3 { match 3 {
$s ... $e => "literal, in range", $s ..= $e => "literal, in range",
_ => "literal, other", _ => "literal, other",
} }
}; };
@ -115,22 +115,22 @@ pub fn main() {
assert_eq!(mtester!('c'), "macro caught literal: c"); assert_eq!(mtester!('c'), "macro caught literal: c");
assert_eq!(mtester!(-1.2), "macro caught literal: -1.2"); assert_eq!(mtester!(-1.2), "macro caught literal: -1.2");
assert_eq!(two_negative_literals!(-2 -3), "macro caught literals: -2, -3"); 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!(match_attr!(#[attr] 1), "attr matched literal");
assert_eq!(test_user!(10, 20), "literal"); assert_eq!(test_user!(10, 20), "literal");
assert_eq!(mtester!(false), "macro caught literal: false"); assert_eq!(mtester!(false), "macro caught literal: false");
assert_eq!(mtester!(true), "macro caught literal: true"); assert_eq!(mtester!(true), "macro caught literal: true");
match_produced_attr!("a"); match_produced_attr!("a");
let _a = LiteralProduced; let _a = LiteralProduced;
assert_eq!(pat_match!(1 ... 3), "literal, in range"); assert_eq!(pat_match!(1 ..= 3), "literal, in range");
assert_eq!(pat_match!(4 ... 6), "literal, other"); assert_eq!(pat_match!(4 ..= 6), "literal, other");
// Cases where 'expr' catches // Cases where 'expr' catches
assert_eq!(mtester!((-1.2)), "macro caught expr: -1.2"); assert_eq!(mtester!((-1.2)), "macro caught expr: -1.2");
assert_eq!(only_expr!(-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!((1 + 3)), "macro caught expr: 4");
assert_eq!(mtester_dbg!(()), "macro caught expr: ()"); 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!(match_attr!(#[attr] (1 + 2)), "attr matched expr");
assert_eq!(test_user!(10, (20 + 2)), "expr"); assert_eq!(test_user!(10, (20 + 2)), "expr");

View file

@ -12,15 +12,15 @@
pub fn main() { pub fn main() {
match 1 { match 1 {
1 ... 3 => {} 1 ..= 3 => {}
_ => panic!("should match range") _ => panic!("should match range")
} }
match 1 { match 1 {
1 ... 3u16 => {} 1 ..= 3u16 => {}
_ => panic!("should match range with inferred start type") _ => panic!("should match range with inferred start type")
} }
match 1 { match 1 {
1u16 ... 3 => {} 1u16 ..= 3 => {}
_ => panic!("should match range with inferred end type") _ => panic!("should match range with inferred end type")
} }
} }

View file

@ -15,7 +15,7 @@ const e: isize = 42;
pub fn main() { pub fn main() {
match 7 { match 7 {
s...e => (), s..=e => (),
_ => (), _ => (),
} }
} }

View file

@ -12,7 +12,7 @@
pub fn main() { pub fn main() {
match 5_usize { match 5_usize {
1_usize...5_usize => {} 1_usize..=5_usize => {}
_ => panic!("should match range"), _ => panic!("should match range"),
} }
match 1_usize { match 1_usize {
@ -20,7 +20,7 @@ pub fn main() {
_ => panic!("should match range start"), _ => panic!("should match range start"),
} }
match 5_usize { match 5_usize {
6_usize...7_usize => panic!("shouldn't match range"), 6_usize..=7_usize => panic!("shouldn't match range"),
_ => {} _ => {}
} }
match 7_usize { match 7_usize {
@ -29,23 +29,23 @@ pub fn main() {
} }
match 5_usize { match 5_usize {
1_usize => panic!("should match non-first range"), 1_usize => panic!("should match non-first range"),
2_usize...6_usize => {} 2_usize..=6_usize => {}
_ => panic!("math is broken") _ => panic!("math is broken")
} }
match 'c' { match 'c' {
'a'...'z' => {} 'a'..='z' => {}
_ => panic!("should suppport char ranges") _ => panic!("should suppport char ranges")
} }
match -3 { match -3 {
-7...5 => {} -7..=5 => {}
_ => panic!("should match signed range") _ => panic!("should match signed range")
} }
match 3.0f64 { match 3.0f64 {
1.0...5.0 => {} 1.0..=5.0 => {}
_ => panic!("should match float range") _ => panic!("should match float range")
} }
match -1.5f64 { match -1.5f64 {
-3.6...3.6 => {} -3.6..=3.6 => {}
_ => panic!("should match negative float range") _ => panic!("should match negative float range")
} }
match 3.5 { match 3.5 {

View file

@ -11,8 +11,8 @@
pub fn main() { pub fn main() {
let i = 5; let i = 5;
match &&&&i { match &&&&i {
1 ... 3 => panic!(), 1 ..= 3 => panic!(),
3 ... 8 => {}, 3 ..= 8 => {},
_ => panic!(), _ => panic!(),
} }
} }

View file

@ -23,13 +23,13 @@ fn main() {
match 10 { match 10 {
1..10 => {}, 1..10 => {},
9...10 => {}, 9..=10 => {},
_ => {}, _ => {},
} }
match 10 { match 10 {
1..10 => {}, 1..10 => {},
10...10 => {}, 10..=10 => {},
_ => {}, _ => {},
} }
@ -42,13 +42,13 @@ fn main() {
match 10 { match 10 {
1..10 => {}, 1..10 => {},
8...9 => {}, 8..=9 => {},
_ => {}, _ => {},
} }
match 10 { match 10 {
1..10 => {}, 1..10 => {},
9...9 => {}, 9..=9 => {},
_ => {}, _ => {},
} }
} }

View file

@ -13,12 +13,12 @@ LL | #![warn(unreachable_patterns)]
warning: unreachable pattern warning: unreachable pattern
--> $DIR/issue-43253.rs:45:9 --> $DIR/issue-43253.rs:45:9
| |
LL | 8...9 => {}, LL | 8..=9 => {},
| ^^^^^ | ^^^^^
warning: unreachable pattern warning: unreachable pattern
--> $DIR/issue-43253.rs:51:9 --> $DIR/issue-43253.rs:51:9
| |
LL | 9...9 => {}, LL | 9..=9 => {},
| ^^^^^ | ^^^^^

View file

@ -13,7 +13,7 @@
fn main() { fn main() {
const MIN: i8 = -5; const MIN: i8 = -5;
match 5i8 { match 5i8 {
MIN...-1 => {}, MIN..=-1 => {},
_ => {}, _ => {},
} }
} }

View file

@ -11,8 +11,8 @@
fn main() { fn main() {
let n: Int = 40; let n: Int = 40;
match n { match n {
0...10 => {}, 0..=10 => {},
10...BAR => {}, //~ ERROR lower range bound must be less than or equal to upper 10..=BAR => {}, //~ ERROR lower range bound must be less than or equal to upper
_ => {}, _ => {},
} }
} }

View file

@ -1,7 +1,7 @@
error[E0030]: lower range bound must be less than or equal to upper error[E0030]: lower range bound must be less than or equal to upper
--> $DIR/ref_to_int_match.rs:15:9 --> $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 | ^^ lower bound larger than upper bound
error: aborting due to previous error error: aborting due to previous error

View file

@ -14,7 +14,7 @@ fn main() {
let s = "hoho"; let s = "hoho";
match s { match s {
"hello" ... "world" => {} "hello" ..= "world" => {}
//~^ ERROR only char and numeric types are allowed in range patterns //~^ ERROR only char and numeric types are allowed in range patterns
_ => {} _ => {}
} }

View file

@ -1,7 +1,7 @@
error[E0029]: only char and numeric types are allowed in range patterns error[E0029]: only char and numeric types are allowed in range patterns
--> $DIR/E0029-teach.rs:17:9 --> $DIR/E0029-teach.rs:17:9
| |
LL | "hello" ... "world" => {} LL | "hello" ..= "world" => {}
| ^^^^^^^^^^^^^^^^^^^ ranges require char or numeric types | ^^^^^^^^^^^^^^^^^^^ ranges require char or numeric types
| |
= note: start type: &'static str = note: start type: &'static str

View file

@ -12,7 +12,7 @@ fn main() {
let s = "hoho"; let s = "hoho";
match s { match s {
"hello" ... "world" => {} "hello" ..= "world" => {}
//~^ ERROR only char and numeric types are allowed in range patterns //~^ ERROR only char and numeric types are allowed in range patterns
_ => {} _ => {}
} }

View file

@ -1,7 +1,7 @@
error[E0029]: only char and numeric types are allowed in range patterns error[E0029]: only char and numeric types are allowed in range patterns
--> $DIR/E0029.rs:15:9 --> $DIR/E0029.rs:15:9
| |
LL | "hello" ... "world" => {} LL | "hello" ..= "world" => {}
| ^^^^^^^^^^^^^^^^^^^ ranges require char or numeric types | ^^^^^^^^^^^^^^^^^^^ ranges require char or numeric types
| |
= note: start type: &'static str = note: start type: &'static str

View file

@ -12,7 +12,7 @@
fn main() { fn main() {
match 5u32 { match 5u32 {
1000 ... 5 => {} 1000 ..= 5 => {}
//~^ ERROR lower range bound must be less than or equal to upper //~^ ERROR lower range bound must be less than or equal to upper
} }
} }

View file

@ -1,7 +1,7 @@
error[E0030]: lower range bound must be less than or equal to upper error[E0030]: lower range bound must be less than or equal to upper
--> $DIR/E0030-teach.rs:15:9 --> $DIR/E0030-teach.rs:15:9
| |
LL | 1000 ... 5 => {} LL | 1000 ..= 5 => {}
| ^^^^ lower bound larger than upper bound | ^^^^ 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. = 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.

View file

@ -11,7 +11,7 @@
fn main() { fn main() {
match 5u32 { match 5u32 {
1000 ... 5 => {} 1000 ..= 5 => {}
//~^ ERROR lower range bound must be less than or equal to upper //~^ ERROR lower range bound must be less than or equal to upper
} }
} }

View file

@ -1,7 +1,7 @@
error[E0030]: lower range bound must be less than or equal to upper error[E0030]: lower range bound must be less than or equal to upper
--> $DIR/E0030.rs:14:9 --> $DIR/E0030.rs:14:9
| |
LL | 1000 ... 5 => {} LL | 1000 ..= 5 => {}
| ^^^^ lower bound larger than upper bound | ^^^^ lower bound larger than upper bound
error: aborting due to previous error error: aborting due to previous error

View file

@ -11,7 +11,7 @@
fn main() { fn main() {
let x = 1u8; let x = 1u8;
match x { match x {
0u8...3i8 => (), //~ ERROR E0308 0u8..=3i8 => (), //~ ERROR E0308
_ => () _ => ()
} }
} }

View file

@ -1,7 +1,7 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/E0308-4.rs:14:9 --> $DIR/E0308-4.rs:14:9
| |
LL | 0u8...3i8 => (), //~ ERROR E0308 LL | 0u8..=3i8 => (), //~ ERROR E0308
| ^^^^^^^^^ expected u8, found i8 | ^^^^^^^^^ expected u8, found i8
error: aborting due to previous error error: aborting due to previous error