Skip to content

Commit ce9d97c

Browse files
committed
---
yaml --- r: 136831 b: refs/heads/dist-snap c: fe93a54 h: refs/heads/master i: 136829: 695d3f9 136827: 9edbc2a 136823: d07ea4a 136815: abd238f 136799: 3bb960d 136767: 353aa33 136703: b8daa17 v: v3
1 parent 5b2ee50 commit ce9d97c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+564
-202
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 189b7332968972f34cdbbbd9b62d97ababf53059
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 0cf60b6bb8fed2cad4407fdf86a49a7eebbd62e6
9+
refs/heads/dist-snap: fe93a549a49983837747986797a40d85ba047cad
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
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
}

branches/dist-snap/src/doc/guide.md

Lines changed: 4 additions & 4 deletions
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
```

branches/dist-snap/src/doc/reference.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,8 @@ The currently implemented features of the reference compiler are:
24412441
* `default_type_params` - Allows use of default type parameters. The future of
24422442
this feature is uncertain.
24432443

2444+
* `if_let` - Allows use of the `if let` syntax.
2445+
24442446
* `intrinsics` - Allows use of the "rust-intrinsics" ABI. Compiler intrinsics
24452447
are inherently unstable and no promise about them is made.
24462448

@@ -3229,7 +3231,7 @@ for i in range(0u, 256) {
32293231
if_expr : "if" no_struct_literal_expr '{' block '}'
32303232
else_tail ? ;
32313233
3232-
else_tail : "else" [ if_expr
3234+
else_tail : "else" [ if_expr | if_let_expr
32333235
| '{' block '}' ] ;
32343236
```
32353237

@@ -3408,7 +3410,7 @@ may be specified with `..`. For example:
34083410
34093411
let message = match x {
34103412
0 | 1 => "not many",
3411-
2 .. 9 => "a few",
3413+
2 ... 9 => "a few",
34123414
_ => "lots"
34133415
};
34143416
```
@@ -3434,6 +3436,19 @@ let message = match maybe_digit {
34343436
};
34353437
```
34363438

3439+
### If let expressions
3440+
3441+
```{.ebnf .gram}
3442+
if_let_expr : "if" "let" pat '=' expr '{' block '}'
3443+
else_tail ? ;
3444+
else_tail : "else" [ if_expr | if_let_expr | '{' block '}' ] ;
3445+
```
3446+
3447+
An `if let` expression is semantically identical to an `if` expression but in place
3448+
of a condition expression it expects a refutable let statement. If the value of the
3449+
expression on the right hand side of the let statement matches the pattern, the corresponding
3450+
block will execute, otherwise flow proceeds to the first `else` block that follows.
3451+
34373452
### Return expressions
34383453

34393454
```{.ebnf .gram}

branches/dist-snap/src/libcollections/string.rs

Lines changed: 7 additions & 7 deletions
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;

branches/dist-snap/src/libcore/char.rs

Lines changed: 5 additions & 5 deletions
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
}

branches/dist-snap/src/libcore/fmt/num.rs

Lines changed: 8 additions & 8 deletions
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
}

branches/dist-snap/src/libcore/str.rs

Lines changed: 7 additions & 7 deletions
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
}

branches/dist-snap/src/libdebug/repr.rs

Lines changed: 1 addition & 1 deletion
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]);

branches/dist-snap/src/libnative/io/tty_windows.rs

Lines changed: 1 addition & 1 deletion
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 };

branches/dist-snap/src/librand/distributions/gamma.rs

Lines changed: 3 additions & 3 deletions
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
}

branches/dist-snap/src/libregex/vm.rs

Lines changed: 1 addition & 1 deletion
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

branches/dist-snap/src/librustc/back/link.rs

Lines changed: 3 additions & 3 deletions
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
_ => {

branches/dist-snap/src/librustc/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,6 @@ register_diagnostics!(
151151
E0157,
152152
E0158,
153153
E0159,
154-
E0161
154+
E0161,
155+
E0162
155156
)

branches/dist-snap/src/librustc/lint/builtin.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,10 @@ impl LintPass for UnnecessaryParens {
10921092
let (value, msg, struct_lit_needs_parens) = match e.node {
10931093
ast::ExprIf(ref cond, _, _) => (cond, "`if` condition", true),
10941094
ast::ExprWhile(ref cond, _, _) => (cond, "`while` condition", true),
1095-
ast::ExprMatch(ref head, _) => (head, "`match` head expression", true),
1095+
ast::ExprMatch(ref head, _, source) => match source {
1096+
ast::MatchNormal => (head, "`match` head expression", true),
1097+
ast::MatchIfLetDesugar => (head, "`if let` head expression", true)
1098+
},
10961099
ast::ExprRet(Some(ref value)) => (value, "`return` value", false),
10971100
ast::ExprAssign(_, ref value) => (value, "assigned value", false),
10981101
ast::ExprAssignOp(_, _, ref value) => (value, "assigned value", false),
@@ -1242,7 +1245,7 @@ impl LintPass for UnusedMut {
12421245

12431246
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
12441247
match e.node {
1245-
ast::ExprMatch(_, ref arms) => {
1248+
ast::ExprMatch(_, ref arms, _) => {
12461249
for a in arms.iter() {
12471250
self.check_unused_mut_pat(cx, a.pats.as_slice())
12481251
}

branches/dist-snap/src/librustc/middle/cfg/construct.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
222222
self.add_node(expr.id, [then_exit, else_exit]) // 4, 5
223223
}
224224

225+
ast::ExprIfLet(..) => {
226+
self.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
227+
}
228+
225229
ast::ExprWhile(ref cond, ref body, _) => {
226230
//
227231
// [pred]
@@ -322,7 +326,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
322326
expr_exit
323327
}
324328

325-
ast::ExprMatch(ref discr, ref arms) => {
329+
ast::ExprMatch(ref discr, ref arms, _) => {
326330
//
327331
// [pred]
328332
// |

branches/dist-snap/src/librustc/middle/check_match.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn check_crate(tcx: &ty::ctxt) {
147147
fn check_expr(cx: &mut MatchCheckCtxt, ex: &Expr) {
148148
visit::walk_expr(cx, ex);
149149
match ex.node {
150-
ExprMatch(ref scrut, ref arms) => {
150+
ExprMatch(ref scrut, ref arms, source) => {
151151
// First, check legality of move bindings.
152152
for arm in arms.iter() {
153153
check_legality_of_move_bindings(cx,
@@ -184,7 +184,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &Expr) {
184184
}
185185

186186
// Fourth, check for unreachable arms.
187-
check_arms(cx, inlined_arms.as_slice());
187+
check_arms(cx, inlined_arms.as_slice(), source);
188188

189189
// Finally, check if the whole match expression is exhaustive.
190190
// Check for empty enum, because is_useful only works on inhabited types.
@@ -252,13 +252,31 @@ fn check_for_static_nan(cx: &MatchCheckCtxt, pats: &[P<Pat>]) {
252252
}
253253

254254
// Check for unreachable patterns
255-
fn check_arms(cx: &MatchCheckCtxt, arms: &[(Vec<P<Pat>>, Option<&Expr>)]) {
255+
fn check_arms(cx: &MatchCheckCtxt, arms: &[(Vec<P<Pat>>, Option<&Expr>)], source: MatchSource) {
256256
let mut seen = Matrix(vec![]);
257+
let mut printed_if_let_err = false;
257258
for &(ref pats, guard) in arms.iter() {
258259
for pat in pats.iter() {
259260
let v = vec![&**pat];
261+
260262
match is_useful(cx, &seen, v.as_slice(), LeaveOutWitness) {
261-
NotUseful => span_err!(cx.tcx.sess, pat.span, E0001, "unreachable pattern"),
263+
NotUseful => {
264+
if source == MatchIfLetDesugar {
265+
if printed_if_let_err {
266+
// we already printed an irrefutable if-let pattern error.
267+
// We don't want two, that's just confusing.
268+
} else {
269+
// find the first arm pattern so we can use its span
270+
let &(ref first_arm_pats, _) = &arms[0];
271+
let first_pat = first_arm_pats.get(0);
272+
let span = first_pat.span;
273+
span_err!(cx.tcx.sess, span, E0162, "irrefutable if-let pattern");
274+
printed_if_let_err = true;
275+
}
276+
} else {
277+
span_err!(cx.tcx.sess, pat.span, E0001, "unreachable pattern");
278+
}
279+
}
262280
Useful => (),
263281
UsefulWithWitness(_) => unreachable!()
264282
}

branches/dist-snap/src/librustc/middle/expr_use_visitor.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,11 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> {
374374
}
375375
}
376376

377-
ast::ExprMatch(ref discr, ref arms) => {
377+
ast::ExprIfLet(..) => {
378+
self.tcx().sess.span_bug(expr.span, "non-desugared ExprIfLet");
379+
}
380+
381+
ast::ExprMatch(ref discr, ref arms, _) => {
378382
let discr_cmt = return_if_err!(self.mc.cat_expr(&**discr));
379383
self.borrow_expr(&**discr, ty::ReEmpty, ty::ImmBorrow, MatchDiscriminant);
380384

0 commit comments

Comments
 (0)