Skip to content

Commit 2bee879

Browse files
committed
---
yaml --- r: 138091 b: refs/heads/try c: b5db97b h: refs/heads/master i: 138089: 125618f 138087: 410c90d v: v3
1 parent 13e3cb4 commit 2bee879

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: b6e0d3a5bf4c88650a22f605f822e02c6b163580
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
5-
refs/heads/try: 45fd623762aca093ab913ed3a8fcd13c5798005d
5+
refs/heads/try: b5db97b354e5b1e1b5d99f513a40493f223fddae
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/test/compile-fail/lint-unnecessary-parens.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
#![deny(unnecessary_parens)]
12-
#![feature(if_let)]
12+
#![feature(if_let,while_let)]
1313

1414
#[deriving(Eq, PartialEq)]
1515
struct X { y: bool }
@@ -34,6 +34,7 @@ fn main() {
3434
_ => {}
3535
}
3636
if let 1i = (1i) {} //~ ERROR unnecessary parentheses around `if let` head expression
37+
while let 1i = (2i) {} //~ ERROR unnecessary parentheses around `while let` head expression
3738
let v = X { y: false };
3839
// struct lits needs parens, so these shouldn't warn.
3940
if (v == X { y: true }) {}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(macro_rules,while_let)]
12+
13+
fn macros() {
14+
macro_rules! foo{
15+
($p:pat, $e:expr, $b:block) => {{
16+
while let $p = $e $b
17+
}}
18+
}
19+
macro_rules! bar{
20+
($p:pat, $e:expr, $b:block) => {{
21+
foo!($p, $e, $b)
22+
}}
23+
}
24+
25+
foo!(a, 1i, { //~ ERROR irrefutable while-let
26+
println!("irrefutable pattern");
27+
});
28+
bar!(a, 1i, { //~ ERROR irrefutable while-let
29+
println!("irrefutable pattern");
30+
});
31+
}
32+
33+
pub fn main() {
34+
while let a = 1i { //~ ERROR irrefutable while-let
35+
println!("irrefutable pattern");
36+
}
37+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(while_let)]
12+
13+
use std::collections::PriorityQueue;
14+
15+
fn make_pq() -> PriorityQueue<int> {
16+
PriorityQueue::from_vec(vec![1i,2,3])
17+
}
18+
19+
pub fn main() {
20+
let mut pq = make_pq();
21+
let mut sum = 0i;
22+
while let Some(x) = pq.pop() {
23+
sum += x;
24+
}
25+
assert_eq!(sum, 6i);
26+
27+
pq = make_pq();
28+
sum = 0;
29+
'a: while let Some(x) = pq.pop() {
30+
sum += x;
31+
if x == 2 {
32+
break 'a;
33+
}
34+
}
35+
assert_eq!(sum, 5i);
36+
37+
pq = make_pq();
38+
sum = 0;
39+
'a: while let Some(x) = pq.pop() {
40+
if x == 3 {
41+
continue 'a;
42+
}
43+
sum += x;
44+
}
45+
assert_eq!(sum, 3i);
46+
47+
let mut pq1 = make_pq();
48+
sum = 0;
49+
while let Some(x) = pq1.pop() {
50+
let mut pq2 = make_pq();
51+
while let Some(y) = pq2.pop() {
52+
sum += x * y;
53+
}
54+
}
55+
assert_eq!(sum, 6i + 12 + 18);
56+
}

0 commit comments

Comments
 (0)