6 #![deny(single_match_else)]
10 enum Foo { Bar, Baz(u8) }
19 static NODE: ExprNode = ExprNode::Unicorns;
21 fn unwrap_addr() -> Option<&'static ExprNode> {
22 match ExprNode::Butterflies { //~ ERROR you seem to be trying to use match
24 ExprNode::ExprAddrOf => Some(&NODE),
35 match x { //~ ERROR you seem to be trying to use match
44 match z { //~ ERROR you seem to be trying to use match
46 (2...3, 7...9) => println!("{:?}", z),
50 // Not linted (pattern guards used)
52 Some(y) if y == 0 => println!("{:?}", y),
56 // Not linted (no block with statements in the single arm)
58 (2...3, 7...9) => println!("{:?}", z),
59 _ => println!("nope"),
63 fn single_match_know_enum() {
65 let y : Result<_, i8> = Ok(1i8);
67 match x { //~ ERROR you seem to be trying to use match
69 Some(y) => println!("{:?}", y),
73 match y { //~ ERROR you seem to be trying to use match
75 Ok(y) => println!("{:?}", y),
79 let c = Cow::Borrowed("");
81 match c { //~ ERROR you seem to be trying to use match
83 Cow::Borrowed(..) => println!("42"),
90 Bar => println!("42"),
95 Baz(_) => println!("42"),
101 let test: bool = true;
104 //~^ ERROR you seem to be trying to match on a boolean expression
106 //~| SUGGESTION if test { 0 } else { 42 };
113 //~^ ERROR you seem to be trying to match on a boolean expression
115 //~| SUGGESTION if option == 1 { 1 } else { 0 };
121 //~^ ERROR you seem to be trying to match on a boolean expression
123 //~^^ SUGGESTION if !test { println!("Noooo!"); };
125 false => { println!("Noooo!"); }
129 //~^ ERROR you seem to be trying to match on a boolean expression
131 //~^^ SUGGESTION if !test { println!("Noooo!"); };
132 false => { println!("Noooo!"); }
137 //~^ ERROR you seem to be trying to match on a boolean expression
139 //~| SUGGESTION if test { println!("Yes!"); } else { println!("Noooo!"); };
140 false => { println!("Noooo!"); }
141 true => { println!("Yes!"); }
156 //~^ERROR add `&` to all patterns
158 //~|SUGGESTION match *v { .. }
159 &Some(v) => println!("{:?}", v),
160 &None => println!("none"),
162 match v { // this doesn't trigger, we have a different pattern
163 &Some(v) => println!("some"),
164 other => println!("other"),
169 //~^ERROR add `&` to all patterns
171 //~|SUGGESTION match *tup { .. }
172 &(v, 1) => println!("{}", v),
173 _ => println!("none"),
175 // special case: using & both in expr and pats
178 //~^ERROR add `&` to both
180 //~|SUGGESTION match w { .. }
181 &Some(v) => println!("{:?}", v),
182 &None => println!("none"),
184 // false positive: only wildcard pattern
187 _ => println!("none"),
192 //~^ERROR add `&` to all patterns
194 //~|SUGGESTION if let .. = *a { .. }
200 //~^ERROR add `&` to both
202 //~|SUGGESTION if let .. = b { .. }
211 0 ... 10 => println!("0 ... 10"), //~ERROR: some ranges overlap
212 0 ... 11 => println!("0 ... 10"),
217 0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap
218 6 ... 7 => println!("6 ... 7"),
219 FOO ... 11 => println!("0 ... 10"),
225 0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap
230 0 ... 10 => println!("0 ... 10"),
231 11 ... 50 => println!("0 ... 10"),
235 if let None = Some(42) {
237 } else if let None = Some(42) {
238 // another nothing :-)