auto merge of #17584 : pcwalton/rust/range-patterns-dotdotdot, r=nick29581
This breaks code that looks like: match foo { 1..3 => { ... } } Instead, write: match foo { 1...3 => { ... } } Closes #17295. r? @nick29581
This commit is contained in:
commit
2f15dcd4d3
35 changed files with 161 additions and 164 deletions
|
@ -1512,7 +1512,7 @@ fn _arm_exec_compiled_test(config: &Config,
|
||||||
for c in exitcode_out.as_slice().chars() {
|
for c in exitcode_out.as_slice().chars() {
|
||||||
if !c.is_digit() { break; }
|
if !c.is_digit() { break; }
|
||||||
exitcode = exitcode * 10 + match c {
|
exitcode = exitcode * 10 + match c {
|
||||||
'0' .. '9' => c as int - ('0' as int),
|
'0' ... '9' => c as int - ('0' as int),
|
||||||
_ => 101,
|
_ => 101,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3757,27 +3757,27 @@ match x {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
You can match a range of values with `..`:
|
You can match a range of values with `...`:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
let x = 1i;
|
let x = 1i;
|
||||||
|
|
||||||
match x {
|
match x {
|
||||||
1 .. 5 => println!("one through five"),
|
1 ... 5 => println!("one through five"),
|
||||||
_ => println!("anything"),
|
_ => println!("anything"),
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Ranges are mostly used with integers and single characters.
|
Ranges are mostly used with integers and single characters.
|
||||||
|
|
||||||
If you're matching multiple things, via a `|` or a `..`, you can bind
|
If you're matching multiple things, via a `|` or a `...`, you can bind
|
||||||
the value to a name with `@`:
|
the value to a name with `@`:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
let x = 1i;
|
let x = 1i;
|
||||||
|
|
||||||
match x {
|
match x {
|
||||||
x @ 1 .. 5 => println!("got {}", x),
|
x @ 1 ... 5 => println!("got {}", x),
|
||||||
_ => println!("anything"),
|
_ => println!("anything"),
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -3410,7 +3410,7 @@ may be specified with `..`. For example:
|
||||||
|
|
||||||
let message = match x {
|
let message = match x {
|
||||||
0 | 1 => "not many",
|
0 | 1 => "not many",
|
||||||
2 .. 9 => "a few",
|
2 ... 9 => "a few",
|
||||||
_ => "lots"
|
_ => "lots"
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
|
@ -199,10 +199,10 @@ impl String {
|
||||||
}
|
}
|
||||||
3 => {
|
3 => {
|
||||||
match (byte, safe_get(v, i, total)) {
|
match (byte, safe_get(v, i, total)) {
|
||||||
(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!();
|
||||||
continue;
|
continue;
|
||||||
|
@ -217,9 +217,9 @@ impl String {
|
||||||
}
|
}
|
||||||
4 => {
|
4 => {
|
||||||
match (byte, safe_get(v, i, total)) {
|
match (byte, safe_get(v, i, total)) {
|
||||||
(0xF0 , 0x90 .. 0xBF) => (),
|
(0xF0 , 0x90 ... 0xBF) => (),
|
||||||
(0xF1 .. 0xF3, 0x80 .. 0xBF) => (),
|
(0xF1 ... 0xF3, 0x80 ... 0xBF) => (),
|
||||||
(0xF4 , 0x80 .. 0x8F) => (),
|
(0xF4 , 0x80 ... 0x8F) => (),
|
||||||
_ => {
|
_ => {
|
||||||
error!();
|
error!();
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -123,9 +123,9 @@ pub fn to_digit(c: char, radix: uint) -> Option<uint> {
|
||||||
fail!("to_digit: radix is too high (maximum 36)");
|
fail!("to_digit: radix is too high (maximum 36)");
|
||||||
}
|
}
|
||||||
let val = match c {
|
let val = match c {
|
||||||
'0' .. '9' => c as uint - ('0' as uint),
|
'0' ... '9' => c as uint - ('0' as uint),
|
||||||
'a' .. 'z' => c as uint + 10u - ('a' as uint),
|
'a' ... 'z' => c as uint + 10u - ('a' as uint),
|
||||||
'A' .. 'Z' => c as uint + 10u - ('A' as uint),
|
'A' ... 'Z' => c as uint + 10u - ('A' as uint),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
if val < radix { Some(val) }
|
if val < radix { Some(val) }
|
||||||
|
@ -184,7 +184,7 @@ pub fn escape_unicode(c: char, f: |char|) {
|
||||||
let offset = offset as uint;
|
let offset = offset as uint;
|
||||||
unsafe {
|
unsafe {
|
||||||
match ((c as i32) >> offset) & 0xf {
|
match ((c as i32) >> offset) & 0xf {
|
||||||
i @ 0 .. 9 => { f(transmute('0' as i32 + i)); }
|
i @ 0 ... 9 => { f(transmute('0' as i32 + i)); }
|
||||||
i => { f(transmute('a' as i32 + (i - 10))); }
|
i => { f(transmute('a' as i32 + (i - 10))); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ pub fn escape_default(c: char, f: |char|) {
|
||||||
'\\' => { f('\\'); f('\\'); }
|
'\\' => { f('\\'); f('\\'); }
|
||||||
'\'' => { f('\\'); f('\''); }
|
'\'' => { f('\\'); f('\''); }
|
||||||
'"' => { f('\\'); f('"'); }
|
'"' => { f('\\'); f('"'); }
|
||||||
'\x20' .. '\x7e' => { f(c); }
|
'\x20' ... '\x7e' => { f(c); }
|
||||||
_ => c.escape_unicode(f),
|
_ => c.escape_unicode(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,13 +99,13 @@ macro_rules! radix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
radix!(Binary, 2, "0b", x @ 0 .. 2 => b'0' + x)
|
radix!(Binary, 2, "0b", x @ 0 ... 2 => b'0' + x)
|
||||||
radix!(Octal, 8, "0o", x @ 0 .. 7 => b'0' + x)
|
radix!(Octal, 8, "0o", x @ 0 ... 7 => b'0' + x)
|
||||||
radix!(Decimal, 10, "", x @ 0 .. 9 => b'0' + x)
|
radix!(Decimal, 10, "", x @ 0 ... 9 => 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))
|
||||||
|
|
||||||
/// A radix with in the range of `2..36`.
|
/// A radix with in the range of `2..36`.
|
||||||
#[deriving(Clone, PartialEq)]
|
#[deriving(Clone, PartialEq)]
|
||||||
|
@ -124,7 +124,7 @@ impl GenericRadix for Radix {
|
||||||
fn base(&self) -> u8 { self.base }
|
fn base(&self) -> u8 { self.base }
|
||||||
fn digit(&self, x: u8) -> u8 {
|
fn digit(&self, x: u8) -> u8 {
|
||||||
match x {
|
match x {
|
||||||
x @ 0 ..9 => b'0' + x,
|
x @ 0 ... 9 => b'0' + x,
|
||||||
x if x < self.base() => b'a' + (x - 10),
|
x if x < self.base() => b'a' + (x - 10),
|
||||||
x => fail!("number not in the range 0..{}: {}", self.base() - 1, x),
|
x => fail!("number not in the range 0..{}: {}", self.base() - 1, x),
|
||||||
}
|
}
|
||||||
|
|
|
@ -843,18 +843,18 @@ fn run_utf8_validation_iterator(iter: &mut slice::Items<u8>) -> bool {
|
||||||
2 => if second & !CONT_MASK != TAG_CONT_U8 {err!()},
|
2 => if second & !CONT_MASK != TAG_CONT_U8 {err!()},
|
||||||
3 => {
|
3 => {
|
||||||
match (first, second, next!() & !CONT_MASK) {
|
match (first, second, next!() & !CONT_MASK) {
|
||||||
(0xE0 , 0xA0 .. 0xBF, TAG_CONT_U8) |
|
(0xE0 , 0xA0 ... 0xBF, TAG_CONT_U8) |
|
||||||
(0xE1 .. 0xEC, 0x80 .. 0xBF, TAG_CONT_U8) |
|
(0xE1 ... 0xEC, 0x80 ... 0xBF, TAG_CONT_U8) |
|
||||||
(0xED , 0x80 .. 0x9F, TAG_CONT_U8) |
|
(0xED , 0x80 ... 0x9F, TAG_CONT_U8) |
|
||||||
(0xEE .. 0xEF, 0x80 .. 0xBF, TAG_CONT_U8) => {}
|
(0xEE ... 0xEF, 0x80 ... 0xBF, TAG_CONT_U8) => {}
|
||||||
_ => err!()
|
_ => err!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
4 => {
|
4 => {
|
||||||
match (first, second, next!() & !CONT_MASK, next!() & !CONT_MASK) {
|
match (first, second, next!() & !CONT_MASK, next!() & !CONT_MASK) {
|
||||||
(0xF0 , 0x90 .. 0xBF, TAG_CONT_U8, TAG_CONT_U8) |
|
(0xF0 , 0x90 ... 0xBF, TAG_CONT_U8, TAG_CONT_U8) |
|
||||||
(0xF1 .. 0xF3, 0x80 .. 0xBF, TAG_CONT_U8, TAG_CONT_U8) |
|
(0xF1 ... 0xF3, 0x80 ... 0xBF, TAG_CONT_U8, TAG_CONT_U8) |
|
||||||
(0xF4 , 0x80 .. 0x8F, TAG_CONT_U8, TAG_CONT_U8) => {}
|
(0xF4 , 0x80 ... 0x8F, TAG_CONT_U8, TAG_CONT_U8) => {}
|
||||||
_ => err!()
|
_ => err!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,7 +227,7 @@ impl<'a> ReprVisitor<'a> {
|
||||||
self.writer.write("\"".as_bytes())
|
self.writer.write("\"".as_bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'\x20'..'\x7e' => self.writer.write([ch as u8]),
|
'\x20'...'\x7e' => self.writer.write([ch as u8]),
|
||||||
_ => {
|
_ => {
|
||||||
char::escape_unicode(ch, |c| {
|
char::escape_unicode(ch, |c| {
|
||||||
let _ = self.writer.write([c as u8]);
|
let _ = self.writer.write([c as u8]);
|
||||||
|
|
|
@ -67,7 +67,7 @@ impl WindowsTTY {
|
||||||
// If the file descriptor is one of stdin, stderr, or stdout
|
// If the file descriptor is one of stdin, stderr, or stdout
|
||||||
// then it should not be closed by us
|
// then it should not be closed by us
|
||||||
let closeme = match fd {
|
let closeme = match fd {
|
||||||
0..2 => false,
|
0...2 => false,
|
||||||
_ => true,
|
_ => true,
|
||||||
};
|
};
|
||||||
let handle = unsafe { get_osfhandle(fd) as HANDLE };
|
let handle = unsafe { get_osfhandle(fd) as HANDLE };
|
||||||
|
|
|
@ -99,7 +99,7 @@ impl Gamma {
|
||||||
|
|
||||||
let repr = match shape {
|
let repr = match shape {
|
||||||
1.0 => One(Exp::new(1.0 / scale)),
|
1.0 => One(Exp::new(1.0 / scale)),
|
||||||
0.0 .. 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
|
0.0 ... 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
|
||||||
_ => Large(GammaLargeShape::new_raw(shape, scale))
|
_ => Large(GammaLargeShape::new_raw(shape, scale))
|
||||||
};
|
};
|
||||||
Gamma { repr: repr }
|
Gamma { repr: repr }
|
||||||
|
|
|
@ -512,7 +512,7 @@ pub fn is_word(c: Option<char>) -> bool {
|
||||||
};
|
};
|
||||||
// Try the common ASCII case before invoking binary search.
|
// Try the common ASCII case before invoking binary search.
|
||||||
match c {
|
match c {
|
||||||
'_' | '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' => true,
|
'_' | '0' ... '9' | 'a' ... 'z' | 'A' ... 'Z' => true,
|
||||||
_ => PERLW.binary_search(|&(start, end)| {
|
_ => PERLW.binary_search(|&(start, end)| {
|
||||||
if c >= start && c <= end {
|
if c >= start && c <= end {
|
||||||
Equal
|
Equal
|
||||||
|
|
|
@ -277,9 +277,9 @@ pub fn sanitize(s: &str) -> String {
|
||||||
'-' | ':' => result.push_char('.'),
|
'-' | ':' => result.push_char('.'),
|
||||||
|
|
||||||
// These are legal symbols
|
// These are legal symbols
|
||||||
'a' .. 'z'
|
'a' ... 'z'
|
||||||
| 'A' .. 'Z'
|
| 'A' ... 'Z'
|
||||||
| '0' .. '9'
|
| '0' ... '9'
|
||||||
| '_' | '.' | '$' => result.push_char(c),
|
| '_' | '.' | '$' => result.push_char(c),
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -110,7 +110,7 @@ impl Svh {
|
||||||
fn hex(b: u64) -> char {
|
fn hex(b: u64) -> char {
|
||||||
let b = (b & 0xf) as u8;
|
let b = (b & 0xf) as u8;
|
||||||
let b = match b {
|
let b = match b {
|
||||||
0 .. 9 => '0' as u8 + b,
|
0 ... 9 => '0' as u8 + b,
|
||||||
_ => 'a' as u8 + b - 10,
|
_ => 'a' as u8 + b - 10,
|
||||||
};
|
};
|
||||||
b as char
|
b as char
|
||||||
|
|
|
@ -224,9 +224,9 @@ impl<'a> FromBase64 for &'a [u8] {
|
||||||
let val = byte as u32;
|
let val = byte as u32;
|
||||||
|
|
||||||
match byte {
|
match byte {
|
||||||
b'A'..b'Z' => buf |= val - 0x41,
|
b'A'...b'Z' => buf |= val - 0x41,
|
||||||
b'a'..b'z' => buf |= val - 0x47,
|
b'a'...b'z' => buf |= val - 0x47,
|
||||||
b'0'..b'9' => buf |= val + 0x04,
|
b'0'...b'9' => buf |= val + 0x04,
|
||||||
b'+' | b'-' => buf |= 0x3E,
|
b'+' | b'-' => buf |= 0x3E,
|
||||||
b'/' | b'_' => buf |= 0x3F,
|
b'/' | b'_' => buf |= 0x3F,
|
||||||
b'\r' | b'\n' => continue,
|
b'\r' | b'\n' => continue,
|
||||||
|
|
|
@ -113,9 +113,9 @@ impl<'a> FromHex for &'a 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
|
||||||
|
|
|
@ -1392,14 +1392,14 @@ impl<T: Iterator<char>> Parser<T> {
|
||||||
|
|
||||||
// A leading '0' must be the only digit before the decimal point.
|
// A leading '0' must be the only digit before the decimal point.
|
||||||
match self.ch_or_null() {
|
match self.ch_or_null() {
|
||||||
'0' .. '9' => return self.error(InvalidNumber),
|
'0' ... '9' => 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 *= 10;
|
accum *= 10;
|
||||||
accum += (c as u64) - ('0' as u64);
|
accum += (c as u64) - ('0' as u64);
|
||||||
|
|
||||||
|
@ -1423,14 +1423,14 @@ impl<T: Iterator<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 int) - ('0' as int)) as f64) * dec;
|
res += (((c as int) - ('0' as int)) as f64) * dec;
|
||||||
self.bump();
|
self.bump();
|
||||||
|
@ -1457,12 +1457,12 @@ impl<T: Iterator<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 uint) - ('0' as uint);
|
exp += (c as uint) - ('0' as uint);
|
||||||
|
|
||||||
|
@ -1488,7 +1488,7 @@ impl<T: Iterator<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,
|
||||||
|
@ -1530,11 +1530,13 @@ impl<T: Iterator<char>> Parser<T> {
|
||||||
'r' => res.push('\r'),
|
'r' => res.push('\r'),
|
||||||
't' => res.push('\t'),
|
't' => res.push('\t'),
|
||||||
'u' => match try!(self.decode_hex_escape()) {
|
'u' => match try!(self.decode_hex_escape()) {
|
||||||
0xDC00 .. 0xDFFF => return self.error(LoneLeadingSurrogateInHexEscape),
|
0xDC00 ... 0xDFFF => {
|
||||||
|
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),
|
||||||
|
@ -1768,7 +1770,7 @@ impl<T: Iterator<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),
|
||||||
|
|
|
@ -199,7 +199,7 @@ pub fn int_to_str_bytes_common<T: Int>(num: T, radix: uint, sign: SignFormat, f:
|
||||||
current_digit_signed
|
current_digit_signed
|
||||||
};
|
};
|
||||||
buf[cur] = match current_digit.to_u8().unwrap() {
|
buf[cur] = match current_digit.to_u8().unwrap() {
|
||||||
i @ 0..9 => b'0' + i,
|
i @ 0...9 => b'0' + i,
|
||||||
i => b'a' + (i - 10),
|
i => b'a' + (i - 10),
|
||||||
};
|
};
|
||||||
cur += 1;
|
cur += 1;
|
||||||
|
|
|
@ -637,7 +637,7 @@ impl<'a> StringReader<'a> {
|
||||||
'b' => { self.bump(); base = 2; num_digits = self.scan_digits(2); }
|
'b' => { self.bump(); base = 2; num_digits = self.scan_digits(2); }
|
||||||
'o' => { self.bump(); base = 8; num_digits = self.scan_digits(8); }
|
'o' => { self.bump(); base = 8; num_digits = self.scan_digits(8); }
|
||||||
'x' => { self.bump(); base = 16; num_digits = self.scan_digits(16); }
|
'x' => { self.bump(); base = 16; num_digits = self.scan_digits(16); }
|
||||||
'0'..'9' | '_' | '.' => {
|
'0'...'9' | '_' | '.' => {
|
||||||
num_digits = self.scan_digits(10) + 1;
|
num_digits = self.scan_digits(10) + 1;
|
||||||
}
|
}
|
||||||
'u' | 'i' => {
|
'u' | 'i' => {
|
||||||
|
|
|
@ -3256,8 +3256,7 @@ impl<'a> Parser<'a> {
|
||||||
// These expressions are limited to literals (possibly
|
// These expressions are limited to literals (possibly
|
||||||
// preceded by unary-minus) or identifiers.
|
// preceded by unary-minus) or identifiers.
|
||||||
let val = self.parse_literal_maybe_minus();
|
let val = self.parse_literal_maybe_minus();
|
||||||
// FIXME(#17295) remove the DOTDOT option.
|
if (self.token == token::DOTDOTDOT) &&
|
||||||
if (self.token == token::DOTDOTDOT || self.token == token::DOTDOT) &&
|
|
||||||
self.look_ahead(1, |t| {
|
self.look_ahead(1, |t| {
|
||||||
*t != token::COMMA && *t != token::RBRACKET
|
*t != token::COMMA && *t != token::RBRACKET
|
||||||
}) {
|
}) {
|
||||||
|
@ -3302,16 +3301,12 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME(#17295) remove the DOTDOT option.
|
if self.look_ahead(1, |t| *t == token::DOTDOTDOT) &&
|
||||||
if self.look_ahead(1, |t| *t == token::DOTDOTDOT || *t == token::DOTDOT) &&
|
|
||||||
self.look_ahead(2, |t| {
|
self.look_ahead(2, |t| {
|
||||||
*t != token::COMMA && *t != token::RBRACKET
|
*t != token::COMMA && *t != token::RBRACKET
|
||||||
}) {
|
}) {
|
||||||
let start = self.parse_expr_res(RestrictionNoBarOp);
|
let start = self.parse_expr_res(RestrictionNoBarOp);
|
||||||
// FIXME(#17295) remove the DOTDOT option (self.eat(&token::DOTDOTDOT)).
|
self.eat(&token::DOTDOTDOT);
|
||||||
if self.token == token::DOTDOTDOT || self.token == token::DOTDOT {
|
|
||||||
self.bump();
|
|
||||||
}
|
|
||||||
let end = self.parse_expr_res(RestrictionNoBarOp);
|
let end = self.parse_expr_res(RestrictionNoBarOp);
|
||||||
pat = PatRange(start, end);
|
pat = PatRange(start, end);
|
||||||
} else if is_plain_ident(&self.token) && !can_be_enum_or_struct {
|
} else if is_plain_ident(&self.token) && !can_be_enum_or_struct {
|
||||||
|
|
|
@ -256,7 +256,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
||||||
if res.is_err() { return res }
|
if res.is_err() { return res }
|
||||||
output.push_all(res.unwrap().as_slice())
|
output.push_all(res.unwrap().as_slice())
|
||||||
} else { return Err("stack is empty".to_string()) },
|
} else { 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 {
|
||||||
|
@ -264,7 +264,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
||||||
'#' => flags.alternate = true,
|
'#' => flags.alternate = true,
|
||||||
' ' => flags.space = true,
|
' ' => flags.space = true,
|
||||||
'.' => fstate = FormatStatePrecision,
|
'.' => fstate = FormatStatePrecision,
|
||||||
'0'..'9' => {
|
'0'...'9' => {
|
||||||
flags.width = cur as uint - '0' as uint;
|
flags.width = cur as uint - '0' as uint;
|
||||||
fstate = FormatStateWidth;
|
fstate = FormatStateWidth;
|
||||||
}
|
}
|
||||||
|
@ -339,7 +339,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
||||||
stack.push(Number(i));
|
stack.push(Number(i));
|
||||||
state = Nothing;
|
state = Nothing;
|
||||||
}
|
}
|
||||||
'0'..'9' => {
|
'0'...'9' => {
|
||||||
state = IntConstant(i*10 + (cur as int - '0' as int));
|
state = IntConstant(i*10 + (cur as int - '0' as int));
|
||||||
old_state = Nothing;
|
old_state = Nothing;
|
||||||
}
|
}
|
||||||
|
@ -368,14 +368,14 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
||||||
(FormatStateFlags,' ') => {
|
(FormatStateFlags,' ') => {
|
||||||
flags.space = true;
|
flags.space = true;
|
||||||
}
|
}
|
||||||
(FormatStateFlags,'0'..'9') => {
|
(FormatStateFlags,'0'...'9') => {
|
||||||
flags.width = cur as uint - '0' as uint;
|
flags.width = cur as uint - '0' as uint;
|
||||||
*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 uint - '0' as uint);
|
flags.width = flags.width * 10 + (cur as uint - '0' as uint);
|
||||||
if flags.width < old { return Err("format width overflow".to_string()) }
|
if flags.width < old { return Err("format width overflow".to_string()) }
|
||||||
|
@ -383,7 +383,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
||||||
(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 uint - '0' as uint);
|
flags.precision = flags.precision * 10 + (cur as uint - '0' as uint);
|
||||||
if flags.precision < old {
|
if flags.precision < old {
|
||||||
|
|
|
@ -447,7 +447,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, String> {
|
||||||
pos = range.next;
|
pos = range.next;
|
||||||
|
|
||||||
match range.ch {
|
match range.ch {
|
||||||
'0' .. '9' => {
|
'0' ... '9' => {
|
||||||
value = value * 10_i32 + (range.ch as i32 - '0' as i32);
|
value = value * 10_i32 + (range.ch as i32 - '0' as i32);
|
||||||
}
|
}
|
||||||
' ' if ws => (),
|
' ' if ws => (),
|
||||||
|
@ -472,7 +472,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, String> {
|
||||||
let range = ss.char_range_at(pos);
|
let range = ss.char_range_at(pos);
|
||||||
|
|
||||||
match range.ch {
|
match range.ch {
|
||||||
'0' .. '9' => {
|
'0' ... '9' => {
|
||||||
pos = range.next;
|
pos = range.next;
|
||||||
// This will drop digits after the nanoseconds place
|
// This will drop digits after the nanoseconds place
|
||||||
let digit = range.ch as i32 - '0' as i32;
|
let digit = range.ch as i32 - '0' as i32;
|
||||||
|
|
|
@ -22,7 +22,7 @@ use tables::{derived_property, property, general_category, conversions, charwidt
|
||||||
/// code point
|
/// code point
|
||||||
pub fn is_alphabetic(c: char) -> bool {
|
pub fn is_alphabetic(c: char) -> bool {
|
||||||
match c {
|
match c {
|
||||||
'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
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) }
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_lowercase(c: char) -> bool {
|
pub fn is_lowercase(c: char) -> bool {
|
||||||
match c {
|
match c {
|
||||||
'a' .. 'z' => true,
|
'a' ... 'z' => true,
|
||||||
c if c > '\x7f' => derived_property::Lowercase(c),
|
c if c > '\x7f' => derived_property::Lowercase(c),
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ pub fn is_lowercase(c: char) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_uppercase(c: char) -> bool {
|
pub fn is_uppercase(c: char) -> bool {
|
||||||
match c {
|
match c {
|
||||||
'A' .. 'Z' => true,
|
'A' ... 'Z' => true,
|
||||||
c if c > '\x7f' => derived_property::Uppercase(c),
|
c if c > '\x7f' => derived_property::Uppercase(c),
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ pub fn is_uppercase(c: char) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_whitespace(c: char) -> bool {
|
pub fn is_whitespace(c: char) -> bool {
|
||||||
match c {
|
match c {
|
||||||
' ' | '\x09' .. '\x0d' => true,
|
' ' | '\x09' ... '\x0d' => true,
|
||||||
c if c > '\x7f' => property::White_Space(c),
|
c if c > '\x7f' => property::White_Space(c),
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ pub fn is_control(c: char) -> bool { general_category::Cc(c) }
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_digit(c: char) -> bool {
|
pub fn is_digit(c: char) -> bool {
|
||||||
match c {
|
match c {
|
||||||
'0' .. '9' => true,
|
'0' ... '9' => true,
|
||||||
c if c > '\x7f' => general_category::N(c),
|
c if c > '\x7f' => general_category::N(c),
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,9 +190,9 @@ fn encode_inner<T: BytesContainer>(c: T, full_url: bool) -> String {
|
||||||
c.container_as_bytes().iter().fold(String::new(), |mut out, &b| {
|
c.container_as_bytes().iter().fold(String::new(), |mut out, &b| {
|
||||||
match b as char {
|
match b as char {
|
||||||
// unreserved:
|
// unreserved:
|
||||||
'A' .. 'Z'
|
'A' ... 'Z'
|
||||||
| 'a' .. 'z'
|
| 'a' ... 'z'
|
||||||
| '0' .. '9'
|
| '0' ... '9'
|
||||||
| '-' | '.' | '_' | '~' => out.push_char(b as char),
|
| '-' | '.' | '_' | '~' => out.push_char(b as char),
|
||||||
|
|
||||||
// gen-delims:
|
// gen-delims:
|
||||||
|
@ -303,9 +303,9 @@ pub fn encode_form_urlencoded(m: &HashMap<String, Vec<String>>) -> String {
|
||||||
fn encode_plus<T: Str>(s: &T) -> String {
|
fn encode_plus<T: Str>(s: &T) -> String {
|
||||||
s.as_slice().bytes().fold(String::new(), |mut out, b| {
|
s.as_slice().bytes().fold(String::new(), |mut out, b| {
|
||||||
match b as char {
|
match b as char {
|
||||||
'A' .. 'Z'
|
'A' ... 'Z'
|
||||||
| 'a' .. 'z'
|
| 'a' ... 'z'
|
||||||
| '0' .. '9'
|
| '0' ... '9'
|
||||||
| '_' | '.' | '-' => out.push_char(b as char),
|
| '_' | '.' | '-' => out.push_char(b as char),
|
||||||
' ' => out.push_char('+'),
|
' ' => out.push_char('+'),
|
||||||
ch => out.push_str(format!("%{:X}", ch as uint).as_slice())
|
ch => out.push_str(format!("%{:X}", ch as uint).as_slice())
|
||||||
|
@ -473,9 +473,9 @@ pub fn query_to_str(query: &Query) -> String {
|
||||||
pub fn get_scheme(rawurl: &str) -> DecodeResult<(&str, &str)> {
|
pub fn get_scheme(rawurl: &str) -> DecodeResult<(&str, &str)> {
|
||||||
for (i,c) in rawurl.chars().enumerate() {
|
for (i,c) in rawurl.chars().enumerate() {
|
||||||
let result = match c {
|
let result = match c {
|
||||||
'A' .. 'Z'
|
'A' ... 'Z'
|
||||||
| 'a' .. 'z' => continue,
|
| 'a' ... 'z' => continue,
|
||||||
'0' .. '9' | '+' | '-' | '.' => {
|
'0' ... '9' | '+' | '-' | '.' => {
|
||||||
if i != 0 { continue }
|
if i != 0 { continue }
|
||||||
|
|
||||||
Err("url: Scheme must begin with a letter.".to_string())
|
Err("url: Scheme must begin with a letter.".to_string())
|
||||||
|
@ -538,15 +538,15 @@ fn get_authority(rawurl: &str) ->
|
||||||
.skip(2) {
|
.skip(2) {
|
||||||
// deal with input class first
|
// deal with input class first
|
||||||
match c {
|
match c {
|
||||||
'0' .. '9' => (),
|
'0' ... '9' => (),
|
||||||
'A' .. 'F'
|
'A' ... 'F'
|
||||||
| 'a' .. 'f' => {
|
| 'a' ... 'f' => {
|
||||||
if input == Digit {
|
if input == Digit {
|
||||||
input = Hex;
|
input = Hex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'G' .. 'Z'
|
'G' ... 'Z'
|
||||||
| 'g' .. 'z'
|
| 'g' ... 'z'
|
||||||
| '-' | '.' | '_' | '~' | '%'
|
| '-' | '.' | '_' | '~' | '%'
|
||||||
| '&' |'\'' | '(' | ')' | '+'
|
| '&' |'\'' | '(' | ')' | '+'
|
||||||
| '!' | '*' | ',' | ';' | '=' => input = Unreserved,
|
| '!' | '*' | ',' | ';' | '=' => input = Unreserved,
|
||||||
|
@ -671,9 +671,9 @@ fn get_path(rawurl: &str, is_authority: bool) -> DecodeResult<(String, &str)> {
|
||||||
let mut end = len;
|
let mut end = len;
|
||||||
for (i,c) in rawurl.chars().enumerate() {
|
for (i,c) in rawurl.chars().enumerate() {
|
||||||
match c {
|
match c {
|
||||||
'A' .. 'Z'
|
'A' ... 'Z'
|
||||||
| 'a' .. 'z'
|
| 'a' ... 'z'
|
||||||
| '0' .. '9'
|
| '0' ... '9'
|
||||||
| '&' |'\'' | '(' | ')' | '.'
|
| '&' |'\'' | '(' | ')' | '.'
|
||||||
| '@' | ':' | '%' | '/' | '+'
|
| '@' | ':' | '%' | '/' | '+'
|
||||||
| '!' | '*' | ',' | ';' | '='
|
| '!' | '*' | ',' | ';' | '='
|
||||||
|
|
|
@ -387,7 +387,7 @@ impl Uuid {
|
||||||
// Make sure all chars are either hex digits or hyphen
|
// Make sure all chars are either hex digits or hyphen
|
||||||
for (i, c) in us.chars().enumerate() {
|
for (i, c) in us.chars().enumerate() {
|
||||||
match c {
|
match c {
|
||||||
'0'..'9' | 'A'..'F' | 'a'..'f' | '-' => {},
|
'0'...'9' | 'A'...'F' | 'a'...'f' | '-' => {},
|
||||||
_ => return Err(ErrorInvalidCharacter(c, i)),
|
_ => return Err(ErrorInvalidCharacter(c, i)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match 1 {
|
match 1 {
|
||||||
1..2u => 1, //~ ERROR mismatched types in range
|
1...2u => 1, //~ ERROR mismatched types in range
|
||||||
_ => 2,
|
_ => 2,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,31 +16,31 @@
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match 5u {
|
match 5u {
|
||||||
1u .. 10u => { }
|
1u ... 10u => { }
|
||||||
5u .. 6u => { }
|
5u ... 6u => { }
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
match 5u {
|
match 5u {
|
||||||
3u .. 6u => { }
|
3u ... 6u => { }
|
||||||
4u .. 6u => { }
|
4u ... 6u => { }
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
match 5u {
|
match 5u {
|
||||||
4u .. 6u => { }
|
4u ... 6u => { }
|
||||||
4u .. 6u => { }
|
4u ... 6u => { }
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
match 'c' {
|
match 'c' {
|
||||||
'A' .. 'z' => {}
|
'A' ... 'z' => {}
|
||||||
'a' .. 'z' => {}
|
'a' ... 'z' => {}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
match 1.0f64 {
|
match 1.0f64 {
|
||||||
0.01f64 .. 6.5f64 => {}
|
0.01f64 ... 6.5f64 => {}
|
||||||
0.02f64 => {}
|
0.02f64 => {}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,16 +14,16 @@
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match 5u {
|
match 5u {
|
||||||
6u .. 1u => { }
|
6u ... 1u => { }
|
||||||
_ => { }
|
_ => { }
|
||||||
};
|
};
|
||||||
|
|
||||||
match "wow" {
|
match "wow" {
|
||||||
"bar" .. "foo" => { }
|
"bar" ... "foo" => { }
|
||||||
};
|
};
|
||||||
|
|
||||||
match 5u {
|
match 5u {
|
||||||
'c' .. 100u => { }
|
'c' ... 100u => { }
|
||||||
_ => { }
|
_ => { }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
|
||||||
fn func((1, (Some(1), 2..3)): (int, (Option<int>, int))) { }
|
fn func((1, (Some(1), 2...3)): (int, (Option<int>, int))) { }
|
||||||
//~^ ERROR refutable pattern in function argument: `(_, _)` not covered
|
//~^ ERROR refutable pattern in function argument: `(_, _)` not covered
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let (1i, (Some(1i), 2i..3i)) = (1i, (None, 2i));
|
let (1i, (Some(1i), 2i...3i)) = (1i, (None, 2i));
|
||||||
//~^ ERROR refutable pattern in local binding: `(_, _)` not covered
|
//~^ ERROR refutable pattern in local binding: `(_, _)` not covered
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
match 100 {
|
match 100 {
|
||||||
b'a' .. b'z' => {},
|
b'a' ... b'z' => {},
|
||||||
_ => fail!()
|
_ => fail!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,21 +11,21 @@
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = 2i;
|
let x = 2i;
|
||||||
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 = 2i;
|
let y = 2i;
|
||||||
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());
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub fn main() {
|
||||||
assert_eq!(3i, match (x, y) {
|
assert_eq!(3i, 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,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ pub fn main() {
|
||||||
assert_eq!(3i, match ((x, y),) {
|
assert_eq!(3i, 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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub fn main() {
|
||||||
fn lit_shadow_range() {
|
fn lit_shadow_range() {
|
||||||
assert_eq!(2i, match 1i {
|
assert_eq!(2i, match 1i {
|
||||||
1 if false => 1i,
|
1 if false => 1i,
|
||||||
1..2 => 2,
|
1...2 => 2,
|
||||||
_ => 3
|
_ => 3
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -39,34 +39,34 @@ fn lit_shadow_range() {
|
||||||
assert_eq!(2i, match x+1 {
|
assert_eq!(2i, match x+1 {
|
||||||
0 => 0i,
|
0 => 0i,
|
||||||
1 if false => 1,
|
1 if false => 1,
|
||||||
1..2 => 2,
|
1...2 => 2,
|
||||||
_ => 3
|
_ => 3
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(2i, match val() {
|
assert_eq!(2i, match val() {
|
||||||
1 if false => 1i,
|
1 if false => 1i,
|
||||||
1..2 => 2,
|
1...2 => 2,
|
||||||
_ => 3
|
_ => 3
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(2i, match CONST {
|
assert_eq!(2i, match CONST {
|
||||||
0 => 0i,
|
0 => 0i,
|
||||||
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!(3i, match 3i {
|
assert_eq!(3i, match 3i {
|
||||||
1 if false => 1i,
|
1 if false => 1i,
|
||||||
1..2 => 2,
|
1...2 => 2,
|
||||||
_ => 3
|
_ => 3
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn range_shadow_lit() {
|
fn range_shadow_lit() {
|
||||||
assert_eq!(2i, match 1i {
|
assert_eq!(2i, match 1i {
|
||||||
1..2 if false => 1i,
|
1...2 if false => 1i,
|
||||||
1 => 2,
|
1 => 2,
|
||||||
_ => 3
|
_ => 3
|
||||||
});
|
});
|
||||||
|
@ -74,27 +74,27 @@ fn range_shadow_lit() {
|
||||||
let x = 0i;
|
let x = 0i;
|
||||||
assert_eq!(2i, match x+1 {
|
assert_eq!(2i, match x+1 {
|
||||||
0 => 0i,
|
0 => 0i,
|
||||||
1..2 if false => 1,
|
1...2 if false => 1,
|
||||||
1 => 2,
|
1 => 2,
|
||||||
_ => 3
|
_ => 3
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(2i, match val() {
|
assert_eq!(2i, match val() {
|
||||||
1..2 if false => 1i,
|
1...2 if false => 1i,
|
||||||
1 => 2,
|
1 => 2,
|
||||||
_ => 3
|
_ => 3
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(2i, match CONST {
|
assert_eq!(2i, match CONST {
|
||||||
0 => 0i,
|
0 => 0i,
|
||||||
1..2 if false => 1,
|
1...2 if false => 1,
|
||||||
1 => 2,
|
1 => 2,
|
||||||
_ => 3
|
_ => 3
|
||||||
});
|
});
|
||||||
|
|
||||||
// ditto
|
// ditto
|
||||||
assert_eq!(3i, match 3i {
|
assert_eq!(3i, match 3i {
|
||||||
1..2 if false => 1i,
|
1...2 if false => 1i,
|
||||||
1 => 2,
|
1 => 2,
|
||||||
_ => 3
|
_ => 3
|
||||||
});
|
});
|
||||||
|
@ -102,36 +102,36 @@ fn range_shadow_lit() {
|
||||||
|
|
||||||
fn range_shadow_range() {
|
fn range_shadow_range() {
|
||||||
assert_eq!(2i, match 1i {
|
assert_eq!(2i, match 1i {
|
||||||
0..2 if false => 1i,
|
0...2 if false => 1i,
|
||||||
1..3 => 2,
|
1...3 => 2,
|
||||||
_ => 3,
|
_ => 3,
|
||||||
});
|
});
|
||||||
|
|
||||||
let x = 0i;
|
let x = 0i;
|
||||||
assert_eq!(2i, match x+1 {
|
assert_eq!(2i, 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!(2i, match val() {
|
assert_eq!(2i, match val() {
|
||||||
0..2 if false => 1,
|
0...2 if false => 1,
|
||||||
1..3 => 2,
|
1...3 => 2,
|
||||||
_ => 3,
|
_ => 3,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(2i, match CONST {
|
assert_eq!(2i, 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!(3i, match 5i {
|
assert_eq!(3i, match 5i {
|
||||||
0..2 if false => 1i,
|
0...2 if false => 1i,
|
||||||
1..3 => 2,
|
1...3 => 2,
|
||||||
_ => 3,
|
_ => 3,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ fn range_shadow_range() {
|
||||||
fn multi_pats_shadow_lit() {
|
fn multi_pats_shadow_lit() {
|
||||||
assert_eq!(2i, match 1i {
|
assert_eq!(2i, match 1i {
|
||||||
100 => 0i,
|
100 => 0i,
|
||||||
0 | 1..10 if false => 1,
|
0 | 1...10 if false => 1,
|
||||||
1 => 2,
|
1 => 2,
|
||||||
_ => 3,
|
_ => 3,
|
||||||
});
|
});
|
||||||
|
@ -148,8 +148,8 @@ fn multi_pats_shadow_lit() {
|
||||||
fn multi_pats_shadow_range() {
|
fn multi_pats_shadow_range() {
|
||||||
assert_eq!(2i, match 1i {
|
assert_eq!(2i, match 1i {
|
||||||
100 => 0i,
|
100 => 0i,
|
||||||
0 | 1..10 if false => 1,
|
0 | 1...10 if false => 1,
|
||||||
1..3 => 2,
|
1...3 => 2,
|
||||||
_ => 3,
|
_ => 3,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ fn lit_shadow_multi_pats() {
|
||||||
assert_eq!(2i, match 1i {
|
assert_eq!(2i, match 1i {
|
||||||
100 => 0i,
|
100 => 0i,
|
||||||
1 if false => 1,
|
1 if false => 1,
|
||||||
0 | 1..10 => 2,
|
0 | 1...10 => 2,
|
||||||
_ => 3,
|
_ => 3,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -166,8 +166,8 @@ fn lit_shadow_multi_pats() {
|
||||||
fn range_shadow_multi_pats() {
|
fn range_shadow_multi_pats() {
|
||||||
assert_eq!(2i, match 1i {
|
assert_eq!(2i, match 1i {
|
||||||
100 => 0i,
|
100 => 0i,
|
||||||
1..3 if false => 1,
|
1...3 if false => 1,
|
||||||
0 | 1..10 => 2,
|
0 | 1...10 => 2,
|
||||||
_ => 3,
|
_ => 3,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,14 @@ enum Foo {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let r = match (FooNullary, 'a') {
|
let r = match (FooNullary, 'a') {
|
||||||
(FooUint(..), 'a'..'z') => 1i,
|
(FooUint(..), 'a'...'z') => 1i,
|
||||||
(FooNullary, 'x') => 2i,
|
(FooNullary, 'x') => 2i,
|
||||||
_ => 0
|
_ => 0
|
||||||
};
|
};
|
||||||
assert_eq!(r, 0);
|
assert_eq!(r, 0);
|
||||||
|
|
||||||
let r = match (FooUint(0), 'a') {
|
let r = match (FooUint(0), 'a') {
|
||||||
(FooUint(1), 'a'..'z') => 1i,
|
(FooUint(1), 'a'...'z') => 1i,
|
||||||
(FooUint(..), 'x') => 2i,
|
(FooUint(..), 'x') => 2i,
|
||||||
(FooNullary, 'a') => 3i,
|
(FooNullary, 'a') => 3i,
|
||||||
_ => 0
|
_ => 0
|
||||||
|
@ -33,7 +33,7 @@ fn main() {
|
||||||
assert_eq!(r, 0);
|
assert_eq!(r, 0);
|
||||||
|
|
||||||
let r = match ('a', FooUint(0)) {
|
let r = match ('a', FooUint(0)) {
|
||||||
('a'..'z', FooUint(1)) => 1i,
|
('a'...'z', FooUint(1)) => 1i,
|
||||||
('x', FooUint(..)) => 2i,
|
('x', FooUint(..)) => 2i,
|
||||||
('a', FooNullary) => 3i,
|
('a', FooNullary) => 3i,
|
||||||
_ => 0
|
_ => 0
|
||||||
|
@ -41,15 +41,15 @@ fn main() {
|
||||||
assert_eq!(r, 0);
|
assert_eq!(r, 0);
|
||||||
|
|
||||||
let r = match ('a', 'a') {
|
let r = match ('a', 'a') {
|
||||||
('a'..'z', 'b') => 1i,
|
('a'...'z', 'b') => 1i,
|
||||||
('x', 'a'..'z') => 2i,
|
('x', 'a'...'z') => 2i,
|
||||||
_ => 0
|
_ => 0
|
||||||
};
|
};
|
||||||
assert_eq!(r, 0);
|
assert_eq!(r, 0);
|
||||||
|
|
||||||
let r = match ('a', 'a') {
|
let r = match ('a', 'a') {
|
||||||
('a'..'z', 'b') => 1i,
|
('a'...'z', 'b') => 1i,
|
||||||
('x', 'a'..'z') => 2i,
|
('x', 'a'...'z') => 2i,
|
||||||
('a', 'a') => 3i,
|
('a', 'a') => 3i,
|
||||||
_ => 0
|
_ => 0
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub fn main() {
|
||||||
static FOO: f64 = 10.0;
|
static FOO: f64 = 10.0;
|
||||||
|
|
||||||
match 0.0 {
|
match 0.0 {
|
||||||
0.0 .. FOO => (),
|
0.0 ... FOO => (),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,32 +12,32 @@
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
match 5u {
|
match 5u {
|
||||||
1u..5u => {}
|
1u...5u => {}
|
||||||
_ => fail!("should match range"),
|
_ => fail!("should match range"),
|
||||||
}
|
}
|
||||||
match 5u {
|
match 5u {
|
||||||
6u..7u => fail!("shouldn't match range"),
|
6u...7u => fail!("shouldn't match range"),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
match 5u {
|
match 5u {
|
||||||
1u => fail!("should match non-first range"),
|
1u => fail!("should match non-first range"),
|
||||||
2u..6u => {}
|
2u...6u => {}
|
||||||
_ => fail!("math is broken")
|
_ => fail!("math is broken")
|
||||||
}
|
}
|
||||||
match 'c' {
|
match 'c' {
|
||||||
'a'..'z' => {}
|
'a'...'z' => {}
|
||||||
_ => fail!("should suppport char ranges")
|
_ => fail!("should suppport char ranges")
|
||||||
}
|
}
|
||||||
match -3i {
|
match -3i {
|
||||||
-7..5 => {}
|
-7...5 => {}
|
||||||
_ => fail!("should match signed range")
|
_ => fail!("should match signed range")
|
||||||
}
|
}
|
||||||
match 3.0f64 {
|
match 3.0f64 {
|
||||||
1.0..5.0 => {}
|
1.0...5.0 => {}
|
||||||
_ => fail!("should match float range")
|
_ => fail!("should match float range")
|
||||||
}
|
}
|
||||||
match -1.5f64 {
|
match -1.5f64 {
|
||||||
-3.6..3.6 => {}
|
-3.6...3.6 => {}
|
||||||
_ => fail!("should match negative float range")
|
_ => fail!("should match negative float range")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue