]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/matches.rs
Extend escape analysis to arguments
[rust.git] / tests / compile-fail / matches.rs
1 #![feature(plugin)]
2
3 #![plugin(clippy)]
4 #![deny(clippy)]
5 #![allow(unused)]
6
7 fn single_match(){
8     let x = Some(1u8);
9     match x {  //~ ERROR you seem to be trying to use match
10                //~^ HELP try
11         Some(y) => {
12             println!("{:?}", y);
13         }
14         _ => ()
15     }
16     // Not linted
17     match x {
18         Some(y) => println!("{:?}", y),
19         None => ()
20     }
21     let z = (1u8,1u8);
22     match z { //~ ERROR you seem to be trying to use match
23               //~^ HELP try
24         (2...3, 7...9) => println!("{:?}", z),
25         _ => {}
26     }
27
28     // Not linted (pattern guards used)
29     match x {
30         Some(y) if y == 0 => println!("{:?}", y),
31         _ => ()
32     }
33
34     // Not linted (content in the else)
35     match z {
36         (2...3, 7...9) => println!("{:?}", z),
37         _ => println!("nope"),
38     }
39 }
40
41 fn match_bool() {
42     let test: bool = true;
43
44     match test {  //~ ERROR you seem to be trying to match on a boolean expression
45         true => (),
46         false => (),
47     };
48
49     let option = 1;
50     match option == 1 {  //~ ERROR you seem to be trying to match on a boolean expression
51         true => 1,
52         false => 0,
53     };
54     
55     match test { //~ ERROR you seem to be trying to match on a boolean expression
56         true => (),
57         false => { println!("Noooo!"); }
58     };
59     
60     match test { //~ ERROR you seem to be trying to match on a boolean expression
61         false => { println!("Noooo!"); }
62         _ => (),
63     };
64     
65     match test { //~ ERROR you seem to be trying to match on a boolean expression
66         false => { println!("Noooo!"); }
67         true => { println!("Yes!"); }
68     };
69
70     // Not linted
71     match option {
72         1 ... 10 => (),
73         10 ... 20 => (),
74         _ => (),
75     };
76 }
77
78 fn ref_pats() {
79     {
80         let v = &Some(0);
81         match v {  //~ERROR dereference the expression: `match *v { ...`
82             &Some(v) => println!("{:?}", v),
83             &None => println!("none"),
84         }
85         match v {  // this doesn't trigger, we have a different pattern
86             &Some(v) => println!("some"),
87             other => println!("other"),
88         }
89     }
90     let tup =& (1, 2);
91     match tup {  //~ERROR dereference the expression: `match *tup { ...`
92         &(v, 1) => println!("{}", v),
93         _ => println!("none"),
94     }
95     // special case: using & both in expr and pats
96     let w = Some(0);
97     match &w {  //~ERROR use `match w { ...`
98         &Some(v) => println!("{:?}", v),
99         &None => println!("none"),
100     }
101     // false positive: only wildcard pattern
102     let w = Some(0);
103     match w {
104         _ => println!("none"),
105     }
106
107     let a = &Some(0);
108     if let &None = a { //~ERROR dereference the expression: `if let ... = *a {`
109         println!("none");
110     }
111
112     let b = Some(0);
113     if let &None = &b { //~ERROR use `if let ... = b {`
114         println!("none");
115     }
116 }
117
118 fn main() {
119 }