File tree 3 files changed +95
-1
lines changed
3 files changed +95
-1
lines changed Original file line number Diff line number Diff line change 9
9
// except according to those terms.
10
10
11
11
#![ deny( unnecessary_parens) ]
12
- #![ feature( if_let) ]
12
+ #![ feature( if_let, while_let ) ]
13
13
14
14
#[ deriving( Eq , PartialEq ) ]
15
15
struct X { y : bool }
@@ -34,6 +34,7 @@ fn main() {
34
34
_ => { }
35
35
}
36
36
if let 1 i = ( 1 i) { } //~ ERROR unnecessary parentheses around `if let` head expression
37
+ while let 1 i = ( 2 i) { } //~ ERROR unnecessary parentheses around `while let` head expression
37
38
let v = X { y : false } ;
38
39
// struct lits needs parens, so these shouldn't warn.
39
40
if ( v == X { y : true } ) { }
Original file line number Diff line number Diff line change
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, 1 i, { //~ ERROR irrefutable while-let
26
+ println!( "irrefutable pattern" ) ;
27
+ } ) ;
28
+ bar ! ( a, 1 i, { //~ ERROR irrefutable while-let
29
+ println!( "irrefutable pattern" ) ;
30
+ } ) ;
31
+ }
32
+
33
+ pub fn main ( ) {
34
+ while let a = 1 i { //~ ERROR irrefutable while-let
35
+ println ! ( "irrefutable pattern" ) ;
36
+ }
37
+ }
Original file line number Diff line number Diff line change
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 ! [ 1 i, 2 , 3 ] )
17
+ }
18
+
19
+ pub fn main ( ) {
20
+ let mut pq = make_pq ( ) ;
21
+ let mut sum = 0 i;
22
+ while let Some ( x) = pq. pop ( ) {
23
+ sum += x;
24
+ }
25
+ assert_eq ! ( sum, 6 i) ;
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, 5 i) ;
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, 3 i) ;
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, 6 i + 12 + 18 ) ;
56
+ }
You can’t perform that action at this time.
0 commit comments