6 #![deny(single_match_else)]
10 enum Foo { Bar, Baz(u8) }
19 static NODE: ExprNode = ExprNode::Unicorns;
24 fn unwrap_addr() -> Option<&'static ExprNode> {
25 match ExprNode::Butterflies {
26 //~^ ERROR you seem to be trying to use match
28 //~| SUGGESTION if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { let x = 5; None }
29 ExprNode::ExprAddrOf => Some(&NODE),
30 _ => { let x = 5; None },
38 //~^ ERROR you seem to be trying to use match
40 //~| SUGGESTION if let Some(y) = x { println!("{:?}", y); };
41 Some(y) => { println!("{:?}", y); }
47 //~^ ERROR you seem to be trying to use match
49 //~| SUGGESTION if let (2...3, 7...9) = z { dummy() };
50 (2...3, 7...9) => dummy(),
54 // Not linted (pattern guards used)
56 Some(y) if y == 0 => println!("{:?}", y),
60 // Not linted (no block with statements in the single arm)
62 (2...3, 7...9) => println!("{:?}", z),
63 _ => println!("nope"),
67 fn single_match_know_enum() {
69 let y : Result<_, i8> = Ok(1i8);
72 //~^ ERROR you seem to be trying to use match
74 //~| SUGGESTION if let Some(y) = x { dummy() };
80 //~^ ERROR you seem to be trying to use match
82 //~| SUGGESTION if let Ok(y) = y { dummy() };
87 let c = Cow::Borrowed("");
90 //~^ ERROR you seem to be trying to use match
92 //~| SUGGESTION if let Cow::Borrowed(..) = c { dummy() };
93 Cow::Borrowed(..) => dummy(),
100 Bar => println!("42"),
105 Baz(_) => println!("42"),
111 let test: bool = true;
114 //~^ ERROR you seem to be trying to match on a boolean expression
116 //~| SUGGESTION if test { 0 } else { 42 };
123 //~^ ERROR you seem to be trying to match on a boolean expression
125 //~| SUGGESTION if option == 1 { 1 } else { 0 };
131 //~^ ERROR you seem to be trying to match on a boolean expression
133 //~^^ SUGGESTION if !test { println!("Noooo!"); };
135 false => { println!("Noooo!"); }
139 //~^ ERROR you seem to be trying to match on a boolean expression
141 //~^^ SUGGESTION if !test { println!("Noooo!"); };
142 false => { println!("Noooo!"); }
147 //~^ ERROR you seem to be trying to match on a boolean expression
149 //~| SUGGESTION if test { println!("Yes!"); } else { println!("Noooo!"); };
150 false => { println!("Noooo!"); }
151 true => { println!("Yes!"); }
166 //~^ERROR add `&` to all patterns
168 //~|SUGGESTION match *v { .. }
169 &Some(v) => println!("{:?}", v),
170 &None => println!("none"),
172 match v { // this doesn't trigger, we have a different pattern
173 &Some(v) => println!("some"),
174 other => println!("other"),
179 //~^ERROR add `&` to all patterns
181 //~|SUGGESTION match *tup { .. }
182 &(v, 1) => println!("{}", v),
183 _ => println!("none"),
185 // special case: using & both in expr and pats
188 //~^ERROR add `&` to both
190 //~|SUGGESTION match w { .. }
191 &Some(v) => println!("{:?}", v),
192 &None => println!("none"),
194 // false positive: only wildcard pattern
197 _ => println!("none"),
202 //~^ERROR add `&` to all patterns
204 //~|SUGGESTION if let .. = *a { .. }
210 //~^ERROR add `&` to both
212 //~|SUGGESTION if let .. = b { .. }
221 0 ... 10 => println!("0 ... 10"), //~ERROR: some ranges overlap
222 0 ... 11 => println!("0 ... 10"), //~NOTE overlaps with this
227 0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap
228 6 ... 7 => println!("6 ... 7"),
229 FOO ... 11 => println!("0 ... 10"), //~NOTE overlaps with this
234 2 => println!("2"), //~NOTE overlaps with this
235 0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap
240 0 ... 10 => println!("0 ... 10"),
241 11 ... 50 => println!("0 ... 10"),
245 if let None = Some(42) {
247 } else if let None = Some(42) {
248 // another nothing :-)