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 && test) { println!("Noooo!"); };
150 //~| ERROR equal expressions as operands
151 false => { println!("Noooo!"); }
156 //~^ ERROR you seem to be trying to match on a boolean expression
158 //~| SUGGESTION if test { println!("Yes!"); } else { println!("Noooo!"); };
159 false => { println!("Noooo!"); }
160 true => { println!("Yes!"); }
175 //~^ERROR add `&` to all patterns
177 //~|SUGGESTION match *v { .. }
178 &Some(v) => println!("{:?}", v),
179 &None => println!("none"),
181 match v { // this doesn't trigger, we have a different pattern
182 &Some(v) => println!("some"),
183 other => println!("other"),
188 //~^ERROR add `&` to all patterns
190 //~|SUGGESTION match *tup { .. }
191 &(v, 1) => println!("{}", v),
192 _ => println!("none"),
194 // special case: using & both in expr and pats
197 //~^ERROR add `&` to both
199 //~|SUGGESTION match w { .. }
200 &Some(v) => println!("{:?}", v),
201 &None => println!("none"),
203 // false positive: only wildcard pattern
206 _ => println!("none"),
211 //~^ERROR add `&` to all patterns
213 //~|SUGGESTION if let .. = *a { .. }
219 //~^ERROR add `&` to both
221 //~|SUGGESTION if let .. = b { .. }
230 0 ... 10 => println!("0 ... 10"), //~ERROR: some ranges overlap
231 0 ... 11 => println!("0 ... 10"), //~NOTE overlaps with this
236 0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap
237 6 ... 7 => println!("6 ... 7"),
238 FOO ... 11 => println!("0 ... 10"), //~NOTE overlaps with this
243 2 => println!("2"), //~NOTE overlaps with this
244 0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap
249 0 ... 10 => println!("0 ... 10"),
250 11 ... 50 => println!("0 ... 10"),
254 if let None = Some(42) {
256 } else if let None = Some(42) {
257 // another nothing :-)