Skip to content

Commit 2f15dcd

Browse files
committed
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
2 parents 57a05cf + 416144b commit 2f15dcd

File tree

35 files changed

+161
-164
lines changed

35 files changed

+161
-164
lines changed

src/compiletest/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ fn _arm_exec_compiled_test(config: &Config,
15121512
for c in exitcode_out.as_slice().chars() {
15131513
if !c.is_digit() { break; }
15141514
exitcode = exitcode * 10 + match c {
1515-
'0' .. '9' => c as int - ('0' as int),
1515+
'0' ... '9' => c as int - ('0' as int),
15161516
_ => 101,
15171517
}
15181518
}

src/doc/guide.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -3757,27 +3757,27 @@ match x {
37573757
}
37583758
```
37593759

3760-
You can match a range of values with `..`:
3760+
You can match a range of values with `...`:
37613761

37623762
```{rust}
37633763
let x = 1i;
37643764
37653765
match x {
3766-
1 .. 5 => println!("one through five"),
3766+
1 ... 5 => println!("one through five"),
37673767
_ => println!("anything"),
37683768
}
37693769
```
37703770

37713771
Ranges are mostly used with integers and single characters.
37723772

3773-
If you're matching multiple things, via a `|` or a `..`, you can bind
3773+
If you're matching multiple things, via a `|` or a `...`, you can bind
37743774
the value to a name with `@`:
37753775

37763776
```{rust}
37773777
let x = 1i;
37783778
37793779
match x {
3780-
x @ 1 .. 5 => println!("got {}", x),
3780+
x @ 1 ... 5 => println!("got {}", x),
37813781
_ => println!("anything"),
37823782
}
37833783
```

src/doc/reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3410,7 +3410,7 @@ may be specified with `..`. For example:
34103410
34113411
let message = match x {
34123412
0 | 1 => "not many",
3413-
2 .. 9 => "a few",
3413+
2 ... 9 => "a few",
34143414
_ => "lots"
34153415
};
34163416
```

src/libcollections/string.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ impl String {
199199
}
200200
3 => {
201201
match (byte, safe_get(v, i, total)) {
202-
(0xE0 , 0xA0 .. 0xBF) => (),
203-
(0xE1 .. 0xEC, 0x80 .. 0xBF) => (),
204-
(0xED , 0x80 .. 0x9F) => (),
205-
(0xEE .. 0xEF, 0x80 .. 0xBF) => (),
202+
(0xE0 , 0xA0 ... 0xBF) => (),
203+
(0xE1 ... 0xEC, 0x80 ... 0xBF) => (),
204+
(0xED , 0x80 ... 0x9F) => (),
205+
(0xEE ... 0xEF, 0x80 ... 0xBF) => (),
206206
_ => {
207207
error!();
208208
continue;
@@ -217,9 +217,9 @@ impl String {
217217
}
218218
4 => {
219219
match (byte, safe_get(v, i, total)) {
220-
(0xF0 , 0x90 .. 0xBF) => (),
221-
(0xF1 .. 0xF3, 0x80 .. 0xBF) => (),
222-
(0xF4 , 0x80 .. 0x8F) => (),
220+
(0xF0 , 0x90 ... 0xBF) => (),
221+
(0xF1 ... 0xF3, 0x80 ... 0xBF) => (),
222+
(0xF4 , 0x80 ... 0x8F) => (),
223223
_ => {
224224
error!();
225225
continue;

src/libcore/char.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ pub fn to_digit(c: char, radix: uint) -> Option<uint> {
123123
fail!("to_digit: radix is too high (maximum 36)");
124124
}
125125
let val = match c {
126-
'0' .. '9' => c as uint - ('0' as uint),
127-
'a' .. 'z' => c as uint + 10u - ('a' as uint),
128-
'A' .. 'Z' => c as uint + 10u - ('A' as uint),
126+
'0' ... '9' => c as uint - ('0' as uint),
127+
'a' ... 'z' => c as uint + 10u - ('a' as uint),
128+
'A' ... 'Z' => c as uint + 10u - ('A' as uint),
129129
_ => return None,
130130
};
131131
if val < radix { Some(val) }
@@ -184,7 +184,7 @@ pub fn escape_unicode(c: char, f: |char|) {
184184
let offset = offset as uint;
185185
unsafe {
186186
match ((c as i32) >> offset) & 0xf {
187-
i @ 0 .. 9 => { f(transmute('0' as i32 + i)); }
187+
i @ 0 ... 9 => { f(transmute('0' as i32 + i)); }
188188
i => { f(transmute('a' as i32 + (i - 10))); }
189189
}
190190
}
@@ -211,7 +211,7 @@ pub fn escape_default(c: char, f: |char|) {
211211
'\\' => { f('\\'); f('\\'); }
212212
'\'' => { f('\\'); f('\''); }
213213
'"' => { f('\\'); f('"'); }
214-
'\x20' .. '\x7e' => { f(c); }
214+
'\x20' ... '\x7e' => { f(c); }
215215
_ => c.escape_unicode(f),
216216
}
217217
}

src/libcore/fmt/num.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ macro_rules! radix {
9999
}
100100
}
101101

102-
radix!(Binary, 2, "0b", x @ 0 .. 2 => b'0' + x)
103-
radix!(Octal, 8, "0o", x @ 0 .. 7 => b'0' + x)
104-
radix!(Decimal, 10, "", x @ 0 .. 9 => b'0' + x)
105-
radix!(LowerHex, 16, "0x", x @ 0 .. 9 => b'0' + x,
106-
x @ 10 ..15 => b'a' + (x - 10))
107-
radix!(UpperHex, 16, "0x", x @ 0 .. 9 => b'0' + x,
108-
x @ 10 ..15 => b'A' + (x - 10))
102+
radix!(Binary, 2, "0b", x @ 0 ... 2 => b'0' + x)
103+
radix!(Octal, 8, "0o", x @ 0 ... 7 => b'0' + x)
104+
radix!(Decimal, 10, "", x @ 0 ... 9 => b'0' + x)
105+
radix!(LowerHex, 16, "0x", x @ 0 ... 9 => b'0' + x,
106+
x @ 10 ... 15 => b'a' + (x - 10))
107+
radix!(UpperHex, 16, "0x", x @ 0 ... 9 => b'0' + x,
108+
x @ 10 ... 15 => b'A' + (x - 10))
109109

110110
/// A radix with in the range of `2..36`.
111111
#[deriving(Clone, PartialEq)]
@@ -124,7 +124,7 @@ impl GenericRadix for Radix {
124124
fn base(&self) -> u8 { self.base }
125125
fn digit(&self, x: u8) -> u8 {
126126
match x {
127-
x @ 0 ..9 => b'0' + x,
127+
x @ 0 ... 9 => b'0' + x,
128128
x if x < self.base() => b'a' + (x - 10),
129129
x => fail!("number not in the range 0..{}: {}", self.base() - 1, x),
130130
}

src/libcore/str.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -843,18 +843,18 @@ fn run_utf8_validation_iterator(iter: &mut slice::Items<u8>) -> bool {
843843
2 => if second & !CONT_MASK != TAG_CONT_U8 {err!()},
844844
3 => {
845845
match (first, second, next!() & !CONT_MASK) {
846-
(0xE0 , 0xA0 .. 0xBF, TAG_CONT_U8) |
847-
(0xE1 .. 0xEC, 0x80 .. 0xBF, TAG_CONT_U8) |
848-
(0xED , 0x80 .. 0x9F, TAG_CONT_U8) |
849-
(0xEE .. 0xEF, 0x80 .. 0xBF, TAG_CONT_U8) => {}
846+
(0xE0 , 0xA0 ... 0xBF, TAG_CONT_U8) |
847+
(0xE1 ... 0xEC, 0x80 ... 0xBF, TAG_CONT_U8) |
848+
(0xED , 0x80 ... 0x9F, TAG_CONT_U8) |
849+
(0xEE ... 0xEF, 0x80 ... 0xBF, TAG_CONT_U8) => {}
850850
_ => err!()
851851
}
852852
}
853853
4 => {
854854
match (first, second, next!() & !CONT_MASK, next!() & !CONT_MASK) {
855-
(0xF0 , 0x90 .. 0xBF, TAG_CONT_U8, TAG_CONT_U8) |
856-
(0xF1 .. 0xF3, 0x80 .. 0xBF, TAG_CONT_U8, TAG_CONT_U8) |
857-
(0xF4 , 0x80 .. 0x8F, TAG_CONT_U8, TAG_CONT_U8) => {}
855+
(0xF0 , 0x90 ... 0xBF, TAG_CONT_U8, TAG_CONT_U8) |
856+
(0xF1 ... 0xF3, 0x80 ... 0xBF, TAG_CONT_U8, TAG_CONT_U8) |
857+
(0xF4 , 0x80 ... 0x8F, TAG_CONT_U8, TAG_CONT_U8) => {}
858858
_ => err!()
859859
}
860860
}

src/libdebug/repr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'a> ReprVisitor<'a> {
227227
self.writer.write("\"".as_bytes())
228228
}
229229
}
230-
'\x20'..'\x7e' => self.writer.write([ch as u8]),
230+
'\x20'...'\x7e' => self.writer.write([ch as u8]),
231231
_ => {
232232
char::escape_unicode(ch, |c| {
233233
let _ = self.writer.write([c as u8]);

src/libnative/io/tty_windows.rs

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

src/librand/distributions/gamma.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ impl Gamma {
9898
assert!(scale > 0.0, "Gamma::new called with scale <= 0");
9999

100100
let repr = match shape {
101-
1.0 => One(Exp::new(1.0 / scale)),
102-
0.0 .. 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
103-
_ => Large(GammaLargeShape::new_raw(shape, scale))
101+
1.0 => One(Exp::new(1.0 / scale)),
102+
0.0 ... 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
103+
_ => Large(GammaLargeShape::new_raw(shape, scale))
104104
};
105105
Gamma { repr: repr }
106106
}

src/libregex/vm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ pub fn is_word(c: Option<char>) -> bool {
512512
};
513513
// Try the common ASCII case before invoking binary search.
514514
match c {
515-
'_' | '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' => true,
515+
'_' | '0' ... '9' | 'a' ... 'z' | 'A' ... 'Z' => true,
516516
_ => PERLW.binary_search(|&(start, end)| {
517517
if c >= start && c <= end {
518518
Equal

src/librustc/back/link.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ pub fn sanitize(s: &str) -> String {
277277
'-' | ':' => result.push_char('.'),
278278

279279
// These are legal symbols
280-
'a' .. 'z'
281-
| 'A' .. 'Z'
282-
| '0' .. '9'
280+
'a' ... 'z'
281+
| 'A' ... 'Z'
282+
| '0' ... '9'
283283
| '_' | '.' | '$' => result.push_char(c),
284284

285285
_ => {

src/librustc_back/svh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl Svh {
110110
fn hex(b: u64) -> char {
111111
let b = (b & 0xf) as u8;
112112
let b = match b {
113-
0 .. 9 => '0' as u8 + b,
113+
0 ... 9 => '0' as u8 + b,
114114
_ => 'a' as u8 + b - 10,
115115
};
116116
b as char

src/libserialize/base64.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ impl<'a> FromBase64 for &'a [u8] {
224224
let val = byte as u32;
225225

226226
match byte {
227-
b'A'..b'Z' => buf |= val - 0x41,
228-
b'a'..b'z' => buf |= val - 0x47,
229-
b'0'..b'9' => buf |= val + 0x04,
227+
b'A'...b'Z' => buf |= val - 0x41,
228+
b'a'...b'z' => buf |= val - 0x47,
229+
b'0'...b'9' => buf |= val + 0x04,
230230
b'+' | b'-' => buf |= 0x3E,
231231
b'/' | b'_' => buf |= 0x3F,
232232
b'\r' | b'\n' => continue,

src/libserialize/hex.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ impl<'a> FromHex for &'a str {
113113
buf <<= 4;
114114

115115
match byte {
116-
b'A'..b'F' => buf |= byte - b'A' + 10,
117-
b'a'..b'f' => buf |= byte - b'a' + 10,
118-
b'0'..b'9' => buf |= byte - b'0',
116+
b'A'...b'F' => buf |= byte - b'A' + 10,
117+
b'a'...b'f' => buf |= byte - b'a' + 10,
118+
b'0'...b'9' => buf |= byte - b'0',
119119
b' '|b'\r'|b'\n'|b'\t' => {
120120
buf >>= 4;
121121
continue

src/libserialize/json.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -1392,14 +1392,14 @@ impl<T: Iterator<char>> Parser<T> {
13921392

13931393
// A leading '0' must be the only digit before the decimal point.
13941394
match self.ch_or_null() {
1395-
'0' .. '9' => return self.error(InvalidNumber),
1395+
'0' ... '9' => return self.error(InvalidNumber),
13961396
_ => ()
13971397
}
13981398
},
1399-
'1' .. '9' => {
1399+
'1' ... '9' => {
14001400
while !self.eof() {
14011401
match self.ch_or_null() {
1402-
c @ '0' .. '9' => {
1402+
c @ '0' ... '9' => {
14031403
accum *= 10;
14041404
accum += (c as u64) - ('0' as u64);
14051405

@@ -1423,14 +1423,14 @@ impl<T: Iterator<char>> Parser<T> {
14231423

14241424
// Make sure a digit follows the decimal place.
14251425
match self.ch_or_null() {
1426-
'0' .. '9' => (),
1426+
'0' ... '9' => (),
14271427
_ => return self.error(InvalidNumber)
14281428
}
14291429

14301430
let mut dec = 1.0;
14311431
while !self.eof() {
14321432
match self.ch_or_null() {
1433-
c @ '0' .. '9' => {
1433+
c @ '0' ... '9' => {
14341434
dec /= 10.0;
14351435
res += (((c as int) - ('0' as int)) as f64) * dec;
14361436
self.bump();
@@ -1457,12 +1457,12 @@ impl<T: Iterator<char>> Parser<T> {
14571457

14581458
// Make sure a digit follows the exponent place.
14591459
match self.ch_or_null() {
1460-
'0' .. '9' => (),
1460+
'0' ... '9' => (),
14611461
_ => return self.error(InvalidNumber)
14621462
}
14631463
while !self.eof() {
14641464
match self.ch_or_null() {
1465-
c @ '0' .. '9' => {
1465+
c @ '0' ... '9' => {
14661466
exp *= 10;
14671467
exp += (c as uint) - ('0' as uint);
14681468

@@ -1488,7 +1488,7 @@ impl<T: Iterator<char>> Parser<T> {
14881488
while i < 4 && !self.eof() {
14891489
self.bump();
14901490
n = match self.ch_or_null() {
1491-
c @ '0' .. '9' => n * 16 + ((c as u16) - ('0' as u16)),
1491+
c @ '0' ... '9' => n * 16 + ((c as u16) - ('0' as u16)),
14921492
'a' | 'A' => n * 16 + 10,
14931493
'b' | 'B' => n * 16 + 11,
14941494
'c' | 'C' => n * 16 + 12,
@@ -1530,11 +1530,13 @@ impl<T: Iterator<char>> Parser<T> {
15301530
'r' => res.push('\r'),
15311531
't' => res.push('\t'),
15321532
'u' => match try!(self.decode_hex_escape()) {
1533-
0xDC00 .. 0xDFFF => return self.error(LoneLeadingSurrogateInHexEscape),
1533+
0xDC00 ... 0xDFFF => {
1534+
return self.error(LoneLeadingSurrogateInHexEscape)
1535+
}
15341536

15351537
// Non-BMP characters are encoded as a sequence of
15361538
// two hex escapes, representing UTF-16 surrogates.
1537-
n1 @ 0xD800 .. 0xDBFF => {
1539+
n1 @ 0xD800 ... 0xDBFF => {
15381540
match (self.next_char(), self.next_char()) {
15391541
(Some('\\'), Some('u')) => (),
15401542
_ => return self.error(UnexpectedEndOfHexEscape),
@@ -1768,7 +1770,7 @@ impl<T: Iterator<char>> Parser<T> {
17681770
'n' => { self.parse_ident("ull", NullValue) }
17691771
't' => { self.parse_ident("rue", BooleanValue(true)) }
17701772
'f' => { self.parse_ident("alse", BooleanValue(false)) }
1771-
'0' .. '9' | '-' => self.parse_number(),
1773+
'0' ... '9' | '-' => self.parse_number(),
17721774
'"' => match self.parse_str() {
17731775
Ok(s) => StringValue(s),
17741776
Err(e) => Error(e),

src/libstd/num/strconv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ pub fn int_to_str_bytes_common<T: Int>(num: T, radix: uint, sign: SignFormat, f:
199199
current_digit_signed
200200
};
201201
buf[cur] = match current_digit.to_u8().unwrap() {
202-
i @ 0..9 => b'0' + i,
203-
i => b'a' + (i - 10),
202+
i @ 0...9 => b'0' + i,
203+
i => b'a' + (i - 10),
204204
};
205205
cur += 1;
206206

src/libsyntax/parse/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl<'a> StringReader<'a> {
637637
'b' => { self.bump(); base = 2; num_digits = self.scan_digits(2); }
638638
'o' => { self.bump(); base = 8; num_digits = self.scan_digits(8); }
639639
'x' => { self.bump(); base = 16; num_digits = self.scan_digits(16); }
640-
'0'..'9' | '_' | '.' => {
640+
'0'...'9' | '_' | '.' => {
641641
num_digits = self.scan_digits(10) + 1;
642642
}
643643
'u' | 'i' => {

src/libsyntax/parse/parser.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -3256,8 +3256,7 @@ impl<'a> Parser<'a> {
32563256
// These expressions are limited to literals (possibly
32573257
// preceded by unary-minus) or identifiers.
32583258
let val = self.parse_literal_maybe_minus();
3259-
// FIXME(#17295) remove the DOTDOT option.
3260-
if (self.token == token::DOTDOTDOT || self.token == token::DOTDOT) &&
3259+
if (self.token == token::DOTDOTDOT) &&
32613260
self.look_ahead(1, |t| {
32623261
*t != token::COMMA && *t != token::RBRACKET
32633262
}) {
@@ -3302,16 +3301,12 @@ impl<'a> Parser<'a> {
33023301
}
33033302
});
33043303

3305-
// FIXME(#17295) remove the DOTDOT option.
3306-
if self.look_ahead(1, |t| *t == token::DOTDOTDOT || *t == token::DOTDOT) &&
3304+
if self.look_ahead(1, |t| *t == token::DOTDOTDOT) &&
33073305
self.look_ahead(2, |t| {
33083306
*t != token::COMMA && *t != token::RBRACKET
33093307
}) {
33103308
let start = self.parse_expr_res(RestrictionNoBarOp);
3311-
// FIXME(#17295) remove the DOTDOT option (self.eat(&token::DOTDOTDOT)).
3312-
if self.token == token::DOTDOTDOT || self.token == token::DOTDOT {
3313-
self.bump();
3314-
}
3309+
self.eat(&token::DOTDOTDOT);
33153310
let end = self.parse_expr_res(RestrictionNoBarOp);
33163311
pat = PatRange(start, end);
33173312
} else if is_plain_ident(&self.token) && !can_be_enum_or_struct {

0 commit comments

Comments
 (0)