librustc: Forbid .. in range patterns.

This breaks code that looks like:

    match foo {
        1..3 => { ... }
    }

Instead, write:

    match foo {
        1...3 => { ... }
    }

Closes #17295.

[breaking-change]
This commit is contained in:
Patrick Walton 2014-09-26 21:13:20 -07:00
parent 38015eeb70
commit 416144b827
35 changed files with 161 additions and 164 deletions

View File

@ -1512,7 +1512,7 @@ fn _arm_exec_compiled_test(config: &Config,
for c in exitcode_out.as_slice().chars() {
if !c.is_digit() { break; }
exitcode = exitcode * 10 + match c {
'0' .. '9' => c as int - ('0' as int),
'0' ... '9' => c as int - ('0' as int),
_ => 101,
}
}

View File

@ -3757,27 +3757,27 @@ match x {
}
```
You can match a range of values with `..`:
You can match a range of values with `...`:
```{rust}
let x = 1i;
match x {
1 .. 5 => println!("one through five"),
1 ... 5 => println!("one through five"),
_ => println!("anything"),
}
```
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 `@`:
```{rust}
let x = 1i;
match x {
x @ 1 .. 5 => println!("got {}", x),
x @ 1 ... 5 => println!("got {}", x),
_ => println!("anything"),
}
```

View File

@ -3408,7 +3408,7 @@ may be specified with `..`. For example:
let message = match x {
0 | 1 => "not many",
2 .. 9 => "a few",
2 ... 9 => "a few",
_ => "lots"
};
```

View File

@ -199,10 +199,10 @@ impl String {
}
3 => {
match (byte, safe_get(v, i, total)) {
(0xE0 , 0xA0 .. 0xBF) => (),
(0xE1 .. 0xEC, 0x80 .. 0xBF) => (),
(0xED , 0x80 .. 0x9F) => (),
(0xEE .. 0xEF, 0x80 .. 0xBF) => (),
(0xE0 , 0xA0 ... 0xBF) => (),
(0xE1 ... 0xEC, 0x80 ... 0xBF) => (),
(0xED , 0x80 ... 0x9F) => (),
(0xEE ... 0xEF, 0x80 ... 0xBF) => (),
_ => {
error!();
continue;
@ -217,9 +217,9 @@ impl String {
}
4 => {
match (byte, safe_get(v, i, total)) {
(0xF0 , 0x90 .. 0xBF) => (),
(0xF1 .. 0xF3, 0x80 .. 0xBF) => (),
(0xF4 , 0x80 .. 0x8F) => (),
(0xF0 , 0x90 ... 0xBF) => (),
(0xF1 ... 0xF3, 0x80 ... 0xBF) => (),
(0xF4 , 0x80 ... 0x8F) => (),
_ => {
error!();
continue;

View File

@ -123,9 +123,9 @@ pub fn to_digit(c: char, radix: uint) -> Option<uint> {
fail!("to_digit: radix is too high (maximum 36)");
}
let val = match c {
'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),
'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),
_ => return None,
};
if val < radix { Some(val) }
@ -184,7 +184,7 @@ pub fn escape_unicode(c: char, f: |char|) {
let offset = offset as uint;
unsafe {
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))); }
}
}
@ -211,7 +211,7 @@ pub fn escape_default(c: char, f: |char|) {
'\\' => { f('\\'); f('\\'); }
'\'' => { f('\\'); f('\''); }
'"' => { f('\\'); f('"'); }
'\x20' .. '\x7e' => { f(c); }
'\x20' ... '\x7e' => { f(c); }
_ => c.escape_unicode(f),
}
}

View File

@ -99,13 +99,13 @@ macro_rules! radix {
}
}
radix!(Binary, 2, "0b", x @ 0 .. 2 => b'0' + x)
radix!(Octal, 8, "0o", x @ 0 .. 7 => b'0' + x)
radix!(Decimal, 10, "", x @ 0 .. 9 => b'0' + x)
radix!(LowerHex, 16, "0x", x @ 0 .. 9 => b'0' + x,
x @ 10 ..15 => b'a' + (x - 10))
radix!(UpperHex, 16, "0x", x @ 0 .. 9 => b'0' + x,
x @ 10 ..15 => b'A' + (x - 10))
radix!(Binary, 2, "0b", x @ 0 ... 2 => b'0' + x)
radix!(Octal, 8, "0o", x @ 0 ... 7 => b'0' + x)
radix!(Decimal, 10, "", x @ 0 ... 9 => b'0' + x)
radix!(LowerHex, 16, "0x", x @ 0 ... 9 => b'0' + x,
x @ 10 ... 15 => b'a' + (x - 10))
radix!(UpperHex, 16, "0x", x @ 0 ... 9 => b'0' + x,
x @ 10 ... 15 => b'A' + (x - 10))
/// A radix with in the range of `2..36`.
#[deriving(Clone, PartialEq)]
@ -124,7 +124,7 @@ impl GenericRadix for Radix {
fn base(&self) -> u8 { self.base }
fn digit(&self, x: u8) -> u8 {
match x {
x @ 0 ..9 => b'0' + x,
x @ 0 ... 9 => b'0' + x,
x if x < self.base() => b'a' + (x - 10),
x => fail!("number not in the range 0..{}: {}", self.base() - 1, x),
}

View File

@ -843,18 +843,18 @@ fn run_utf8_validation_iterator(iter: &mut slice::Items<u8>) -> bool {
2 => if second & !CONT_MASK != TAG_CONT_U8 {err!()},
3 => {
match (first, second, next!() & !CONT_MASK) {
(0xE0 , 0xA0 .. 0xBF, TAG_CONT_U8) |
(0xE1 .. 0xEC, 0x80 .. 0xBF, TAG_CONT_U8) |
(0xED , 0x80 .. 0x9F, TAG_CONT_U8) |
(0xEE .. 0xEF, 0x80 .. 0xBF, TAG_CONT_U8) => {}
(0xE0 , 0xA0 ... 0xBF, TAG_CONT_U8) |
(0xE1 ... 0xEC, 0x80 ... 0xBF, TAG_CONT_U8) |
(0xED , 0x80 ... 0x9F, TAG_CONT_U8) |
(0xEE ... 0xEF, 0x80 ... 0xBF, TAG_CONT_U8) => {}
_ => err!()
}
}
4 => {
match (first, second, next!() & !CONT_MASK, next!() & !CONT_MASK) {
(0xF0 , 0x90 .. 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) => {}
(0xF0 , 0x90 ... 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) => {}
_ => err!()
}
}

View File

@ -227,7 +227,7 @@ impl<'a> ReprVisitor<'a> {
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| {
let _ = self.writer.write([c as u8]);

View File

@ -67,7 +67,7 @@ impl WindowsTTY {
// If the file descriptor is one of stdin, stderr, or stdout
// then it should not be closed by us
let closeme = match fd {
0..2 => false,
0...2 => false,
_ => true,
};
let handle = unsafe { get_osfhandle(fd) as HANDLE };

View File

@ -98,9 +98,9 @@ impl Gamma {
assert!(scale > 0.0, "Gamma::new called with scale <= 0");
let repr = match shape {
1.0 => One(Exp::new(1.0 / scale)),
0.0 .. 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
_ => Large(GammaLargeShape::new_raw(shape, scale))
1.0 => One(Exp::new(1.0 / scale)),
0.0 ... 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
_ => Large(GammaLargeShape::new_raw(shape, scale))
};
Gamma { repr: repr }
}

View File

@ -512,7 +512,7 @@ pub fn is_word(c: Option<char>) -> bool {
};
// Try the common ASCII case before invoking binary search.
match c {
'_' | '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' => true,
'_' | '0' ... '9' | 'a' ... 'z' | 'A' ... 'Z' => true,
_ => PERLW.binary_search(|&(start, end)| {
if c >= start && c <= end {
Equal

View File

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

View File

@ -110,7 +110,7 @@ impl Svh {
fn hex(b: u64) -> char {
let b = (b & 0xf) as u8;
let b = match b {
0 .. 9 => '0' as u8 + b,
0 ... 9 => '0' as u8 + b,
_ => 'a' as u8 + b - 10,
};
b as char

View File

@ -224,9 +224,9 @@ impl<'a> FromBase64 for &'a [u8] {
let val = byte as u32;
match byte {
b'A'..b'Z' => buf |= val - 0x41,
b'a'..b'z' => buf |= val - 0x47,
b'0'..b'9' => buf |= val + 0x04,
b'A'...b'Z' => buf |= val - 0x41,
b'a'...b'z' => buf |= val - 0x47,
b'0'...b'9' => buf |= val + 0x04,
b'+' | b'-' => buf |= 0x3E,
b'/' | b'_' => buf |= 0x3F,
b'\r' | b'\n' => continue,

View File

@ -113,9 +113,9 @@ impl<'a> FromHex for &'a str {
buf <<= 4;
match byte {
b'A'..b'F' => buf |= byte - b'A' + 10,
b'a'..b'f' => buf |= byte - b'a' + 10,
b'0'..b'9' => buf |= byte - b'0',
b'A'...b'F' => buf |= byte - b'A' + 10,
b'a'...b'f' => buf |= byte - b'a' + 10,
b'0'...b'9' => buf |= byte - b'0',
b' '|b'\r'|b'\n'|b'\t' => {
buf >>= 4;
continue

View File

@ -1392,14 +1392,14 @@ impl<T: Iterator<char>> Parser<T> {
// A leading '0' must be the only digit before the decimal point.
match self.ch_or_null() {
'0' .. '9' => return self.error(InvalidNumber),
'0' ... '9' => return self.error(InvalidNumber),
_ => ()
}
},
'1' .. '9' => {
'1' ... '9' => {
while !self.eof() {
match self.ch_or_null() {
c @ '0' .. '9' => {
c @ '0' ... '9' => {
accum *= 10;
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.
match self.ch_or_null() {
'0' .. '9' => (),
'0' ... '9' => (),
_ => return self.error(InvalidNumber)
}
let mut dec = 1.0;
while !self.eof() {
match self.ch_or_null() {
c @ '0' .. '9' => {
c @ '0' ... '9' => {
dec /= 10.0;
res += (((c as int) - ('0' as int)) as f64) * dec;
self.bump();
@ -1457,12 +1457,12 @@ impl<T: Iterator<char>> Parser<T> {
// Make sure a digit follows the exponent place.
match self.ch_or_null() {
'0' .. '9' => (),
'0' ... '9' => (),
_ => return self.error(InvalidNumber)
}
while !self.eof() {
match self.ch_or_null() {
c @ '0' .. '9' => {
c @ '0' ... '9' => {
exp *= 10;
exp += (c as uint) - ('0' as uint);
@ -1488,7 +1488,7 @@ impl<T: Iterator<char>> Parser<T> {
while i < 4 && !self.eof() {
self.bump();
n = match self.ch_or_null() {
c @ '0' .. '9' => n * 16 + ((c as u16) - ('0' as u16)),
c @ '0' ... '9' => n * 16 + ((c as u16) - ('0' as u16)),
'a' | 'A' => n * 16 + 10,
'b' | 'B' => n * 16 + 11,
'c' | 'C' => n * 16 + 12,
@ -1530,11 +1530,13 @@ impl<T: Iterator<char>> Parser<T> {
'r' => res.push('\r'),
't' => res.push('\t'),
'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
// two hex escapes, representing UTF-16 surrogates.
n1 @ 0xD800 .. 0xDBFF => {
n1 @ 0xD800 ... 0xDBFF => {
match (self.next_char(), self.next_char()) {
(Some('\\'), Some('u')) => (),
_ => return self.error(UnexpectedEndOfHexEscape),
@ -1768,7 +1770,7 @@ impl<T: Iterator<char>> Parser<T> {
'n' => { self.parse_ident("ull", NullValue) }
't' => { self.parse_ident("rue", BooleanValue(true)) }
'f' => { self.parse_ident("alse", BooleanValue(false)) }
'0' .. '9' | '-' => self.parse_number(),
'0' ... '9' | '-' => self.parse_number(),
'"' => match self.parse_str() {
Ok(s) => StringValue(s),
Err(e) => Error(e),

View File

@ -199,8 +199,8 @@ pub fn int_to_str_bytes_common<T: Int>(num: T, radix: uint, sign: SignFormat, f:
current_digit_signed
};
buf[cur] = match current_digit.to_u8().unwrap() {
i @ 0..9 => b'0' + i,
i => b'a' + (i - 10),
i @ 0...9 => b'0' + i,
i => b'a' + (i - 10),
};
cur += 1;

View File

@ -637,7 +637,7 @@ impl<'a> StringReader<'a> {
'b' => { self.bump(); base = 2; num_digits = self.scan_digits(2); }
'o' => { self.bump(); base = 8; num_digits = self.scan_digits(8); }
'x' => { self.bump(); base = 16; num_digits = self.scan_digits(16); }
'0'..'9' | '_' | '.' => {
'0'...'9' | '_' | '.' => {
num_digits = self.scan_digits(10) + 1;
}
'u' | 'i' => {

View File

@ -3237,8 +3237,7 @@ impl<'a> Parser<'a> {
// These expressions are limited to literals (possibly
// preceded by unary-minus) or identifiers.
let val = self.parse_literal_maybe_minus();
// FIXME(#17295) remove the DOTDOT option.
if (self.token == token::DOTDOTDOT || self.token == token::DOTDOT) &&
if (self.token == token::DOTDOTDOT) &&
self.look_ahead(1, |t| {
*t != token::COMMA && *t != token::RBRACKET
}) {
@ -3283,16 +3282,12 @@ impl<'a> Parser<'a> {
}
});
// FIXME(#17295) remove the DOTDOT option.
if self.look_ahead(1, |t| *t == token::DOTDOTDOT || *t == token::DOTDOT) &&
if self.look_ahead(1, |t| *t == token::DOTDOTDOT) &&
self.look_ahead(2, |t| {
*t != token::COMMA && *t != token::RBRACKET
}) {
let start = self.parse_expr_res(RestrictionNoBarOp);
// FIXME(#17295) remove the DOTDOT option (self.eat(&token::DOTDOTDOT)).
if self.token == token::DOTDOTDOT || self.token == token::DOTDOT {
self.bump();
}
self.eat(&token::DOTDOTDOT);
let end = self.parse_expr_res(RestrictionNoBarOp);
pat = PatRange(start, end);
} else if is_plain_ident(&self.token) && !can_be_enum_or_struct {

View File

@ -256,7 +256,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
if res.is_err() { return res }
output.push_all(res.unwrap().as_slice())
} else { return Err("stack is empty".to_string()) },
':'|'#'|' '|'.'|'0'..'9' => {
':'|'#'|' '|'.'|'0'...'9' => {
let mut flags = Flags::new();
let mut fstate = FormatStateFlags;
match cur {
@ -264,7 +264,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
'#' => flags.alternate = true,
' ' => flags.space = true,
'.' => fstate = FormatStatePrecision,
'0'..'9' => {
'0'...'9' => {
flags.width = cur as uint - '0' as uint;
fstate = FormatStateWidth;
}
@ -339,7 +339,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
stack.push(Number(i));
state = Nothing;
}
'0'..'9' => {
'0'...'9' => {
state = IntConstant(i*10 + (cur as int - '0' as int));
old_state = Nothing;
}
@ -368,14 +368,14 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
(FormatStateFlags,' ') => {
flags.space = true;
}
(FormatStateFlags,'0'..'9') => {
(FormatStateFlags,'0'...'9') => {
flags.width = cur as uint - '0' as uint;
*fstate = FormatStateWidth;
}
(FormatStateFlags,'.') => {
*fstate = FormatStatePrecision;
}
(FormatStateWidth,'0'..'9') => {
(FormatStateWidth,'0'...'9') => {
let old = flags.width;
flags.width = flags.width * 10 + (cur as uint - '0' as uint);
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,'.') => {
*fstate = FormatStatePrecision;
}
(FormatStatePrecision,'0'..'9') => {
(FormatStatePrecision,'0'...'9') => {
let old = flags.precision;
flags.precision = flags.precision * 10 + (cur as uint - '0' as uint);
if flags.precision < old {

View File

@ -447,7 +447,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, String> {
pos = range.next;
match range.ch {
'0' .. '9' => {
'0' ... '9' => {
value = value * 10_i32 + (range.ch as i32 - '0' as i32);
}
' ' if ws => (),
@ -472,7 +472,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, String> {
let range = ss.char_range_at(pos);
match range.ch {
'0' .. '9' => {
'0' ... '9' => {
pos = range.next;
// This will drop digits after the nanoseconds place
let digit = range.ch as i32 - '0' as i32;

View File

@ -22,7 +22,7 @@ use tables::{derived_property, property, general_category, conversions, charwidt
/// code point
pub fn is_alphabetic(c: char) -> bool {
match c {
'a' .. 'z' | 'A' .. 'Z' => true,
'a' ... 'z' | 'A' ... 'Z' => true,
c if c > '\x7f' => derived_property::Alphabetic(c),
_ => false
}
@ -52,7 +52,7 @@ pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) }
#[inline]
pub fn is_lowercase(c: char) -> bool {
match c {
'a' .. 'z' => true,
'a' ... 'z' => true,
c if c > '\x7f' => derived_property::Lowercase(c),
_ => false
}
@ -66,7 +66,7 @@ pub fn is_lowercase(c: char) -> bool {
#[inline]
pub fn is_uppercase(c: char) -> bool {
match c {
'A' .. 'Z' => true,
'A' ... 'Z' => true,
c if c > '\x7f' => derived_property::Uppercase(c),
_ => false
}
@ -80,7 +80,7 @@ pub fn is_uppercase(c: char) -> bool {
#[inline]
pub fn is_whitespace(c: char) -> bool {
match c {
' ' | '\x09' .. '\x0d' => true,
' ' | '\x09' ... '\x0d' => true,
c if c > '\x7f' => property::White_Space(c),
_ => false
}
@ -111,7 +111,7 @@ pub fn is_control(c: char) -> bool { general_category::Cc(c) }
#[inline]
pub fn is_digit(c: char) -> bool {
match c {
'0' .. '9' => true,
'0' ... '9' => true,
c if c > '\x7f' => general_category::N(c),
_ => false
}

View File

@ -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| {
match b as char {
// unreserved:
'A' .. 'Z'
| 'a' .. 'z'
| '0' .. '9'
'A' ... 'Z'
| 'a' ... 'z'
| '0' ... '9'
| '-' | '.' | '_' | '~' => out.push_char(b as char),
// 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 {
s.as_slice().bytes().fold(String::new(), |mut out, b| {
match b as char {
'A' .. 'Z'
| 'a' .. 'z'
| '0' .. '9'
'A' ... 'Z'
| 'a' ... 'z'
| '0' ... '9'
| '_' | '.' | '-' => out.push_char(b as char),
' ' => out.push_char('+'),
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)> {
for (i,c) in rawurl.chars().enumerate() {
let result = match c {
'A' .. 'Z'
| 'a' .. 'z' => continue,
'0' .. '9' | '+' | '-' | '.' => {
'A' ... 'Z'
| 'a' ... 'z' => continue,
'0' ... '9' | '+' | '-' | '.' => {
if i != 0 { continue }
Err("url: Scheme must begin with a letter.".to_string())
@ -538,15 +538,15 @@ fn get_authority(rawurl: &str) ->
.skip(2) {
// deal with input class first
match c {
'0' .. '9' => (),
'A' .. 'F'
| 'a' .. 'f' => {
'0' ... '9' => (),
'A' ... 'F'
| 'a' ... 'f' => {
if input == Digit {
input = Hex;
}
}
'G' .. 'Z'
| 'g' .. 'z'
'G' ... 'Z'
| 'g' ... 'z'
| '-' | '.' | '_' | '~' | '%'
| '&' |'\'' | '(' | ')' | '+'
| '!' | '*' | ',' | ';' | '=' => input = Unreserved,
@ -671,9 +671,9 @@ fn get_path(rawurl: &str, is_authority: bool) -> DecodeResult<(String, &str)> {
let mut end = len;
for (i,c) in rawurl.chars().enumerate() {
match c {
'A' .. 'Z'
| 'a' .. 'z'
| '0' .. '9'
'A' ... 'Z'
| 'a' ... 'z'
| '0' ... '9'
| '&' |'\'' | '(' | ')' | '.'
| '@' | ':' | '%' | '/' | '+'
| '!' | '*' | ',' | ';' | '='

View File

@ -387,7 +387,7 @@ impl Uuid {
// Make sure all chars are either hex digits or hyphen
for (i, c) in us.chars().enumerate() {
match c {
'0'..'9' | 'A'..'F' | 'a'..'f' | '-' => {},
'0'...'9' | 'A'...'F' | 'a'...'f' | '-' => {},
_ => return Err(ErrorInvalidCharacter(c, i)),
}
}

View File

@ -10,7 +10,7 @@
fn main() {
match 1 {
1..2u => 1, //~ ERROR mismatched types in range
1...2u => 1, //~ ERROR mismatched types in range
_ => 2,
};
}

View File

@ -16,31 +16,31 @@
fn main() {
match 5u {
1u .. 10u => { }
5u .. 6u => { }
1u ... 10u => { }
5u ... 6u => { }
_ => {}
};
match 5u {
3u .. 6u => { }
4u .. 6u => { }
3u ... 6u => { }
4u ... 6u => { }
_ => {}
};
match 5u {
4u .. 6u => { }
4u .. 6u => { }
4u ... 6u => { }
4u ... 6u => { }
_ => {}
};
match 'c' {
'A' .. 'z' => {}
'a' .. 'z' => {}
'A' ... 'z' => {}
'a' ... 'z' => {}
_ => {}
};
match 1.0f64 {
0.01f64 .. 6.5f64 => {}
0.01f64 ... 6.5f64 => {}
0.02f64 => {}
_ => {}
};

View File

@ -14,16 +14,16 @@
fn main() {
match 5u {
6u .. 1u => { }
6u ... 1u => { }
_ => { }
};
match "wow" {
"bar" .. "foo" => { }
"bar" ... "foo" => { }
};
match 5u {
'c' .. 100u => { }
'c' ... 100u => { }
_ => { }
};
}

View File

@ -9,10 +9,10 @@
// 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
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
}

View File

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

View File

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

View File

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

View File

@ -31,7 +31,7 @@ pub fn main() {
fn lit_shadow_range() {
assert_eq!(2i, match 1i {
1 if false => 1i,
1..2 => 2,
1...2 => 2,
_ => 3
});
@ -39,34 +39,34 @@ fn lit_shadow_range() {
assert_eq!(2i, match x+1 {
0 => 0i,
1 if false => 1,
1..2 => 2,
1...2 => 2,
_ => 3
});
assert_eq!(2i, match val() {
1 if false => 1i,
1..2 => 2,
1...2 => 2,
_ => 3
});
assert_eq!(2i, match CONST {
0 => 0i,
1 if false => 1,
1..2 => 2,
1...2 => 2,
_ => 3
});
// value is out of the range of second arm, should match wildcard pattern
assert_eq!(3i, match 3i {
1 if false => 1i,
1..2 => 2,
1...2 => 2,
_ => 3
});
}
fn range_shadow_lit() {
assert_eq!(2i, match 1i {
1..2 if false => 1i,
1...2 if false => 1i,
1 => 2,
_ => 3
});
@ -74,27 +74,27 @@ fn range_shadow_lit() {
let x = 0i;
assert_eq!(2i, match x+1 {
0 => 0i,
1..2 if false => 1,
1...2 if false => 1,
1 => 2,
_ => 3
});
assert_eq!(2i, match val() {
1..2 if false => 1i,
1...2 if false => 1i,
1 => 2,
_ => 3
});
assert_eq!(2i, match CONST {
0 => 0i,
1..2 if false => 1,
1...2 if false => 1,
1 => 2,
_ => 3
});
// ditto
assert_eq!(3i, match 3i {
1..2 if false => 1i,
1...2 if false => 1i,
1 => 2,
_ => 3
});
@ -102,36 +102,36 @@ fn range_shadow_lit() {
fn range_shadow_range() {
assert_eq!(2i, match 1i {
0..2 if false => 1i,
1..3 => 2,
0...2 if false => 1i,
1...3 => 2,
_ => 3,
});
let x = 0i;
assert_eq!(2i, match x+1 {
100 => 0,
0..2 if false => 1,
1..3 => 2,
0...2 if false => 1,
1...3 => 2,
_ => 3,
});
assert_eq!(2i, match val() {
0..2 if false => 1,
1..3 => 2,
0...2 if false => 1,
1...3 => 2,
_ => 3,
});
assert_eq!(2i, match CONST {
100 => 0,
0..2 if false => 1,
1..3 => 2,
0...2 if false => 1,
1...3 => 2,
_ => 3,
});
// ditto
assert_eq!(3i, match 5i {
0..2 if false => 1i,
1..3 => 2,
0...2 if false => 1i,
1...3 => 2,
_ => 3,
});
}
@ -139,7 +139,7 @@ fn range_shadow_range() {
fn multi_pats_shadow_lit() {
assert_eq!(2i, match 1i {
100 => 0i,
0 | 1..10 if false => 1,
0 | 1...10 if false => 1,
1 => 2,
_ => 3,
});
@ -148,8 +148,8 @@ fn multi_pats_shadow_lit() {
fn multi_pats_shadow_range() {
assert_eq!(2i, match 1i {
100 => 0i,
0 | 1..10 if false => 1,
1..3 => 2,
0 | 1...10 if false => 1,
1...3 => 2,
_ => 3,
});
}
@ -158,7 +158,7 @@ fn lit_shadow_multi_pats() {
assert_eq!(2i, match 1i {
100 => 0i,
1 if false => 1,
0 | 1..10 => 2,
0 | 1...10 => 2,
_ => 3,
});
}
@ -166,8 +166,8 @@ fn lit_shadow_multi_pats() {
fn range_shadow_multi_pats() {
assert_eq!(2i, match 1i {
100 => 0i,
1..3 if false => 1,
0 | 1..10 => 2,
1...3 if false => 1,
0 | 1...10 => 2,
_ => 3,
});
}

View File

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

View File

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

View File

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