Skip to content

Commit 9e76bce

Browse files
committed
Improve matches tests
1 parent eba449c commit 9e76bce

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

tests/compile-fail/matches.rs

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,38 @@ enum ExprNode {
1818

1919
static NODE: ExprNode = ExprNode::Unicorns;
2020

21+
fn dummy() {
22+
}
23+
2124
fn unwrap_addr() -> Option<&'static ExprNode> {
22-
match ExprNode::Butterflies { //~ ERROR you seem to be trying to use match
23-
//~^ HELP try
25+
match ExprNode::Butterflies {
26+
//~^ ERROR you seem to be trying to use match
27+
//~| HELP try
28+
//~| SUGGESTION if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { let x = 5; None }
2429
ExprNode::ExprAddrOf => Some(&NODE),
25-
_ => {
26-
let x = 5;
27-
None
28-
},
30+
_ => { let x = 5; None },
2931
}
3032
}
3133

3234
fn single_match(){
3335
let x = Some(1u8);
3436

35-
match x { //~ ERROR you seem to be trying to use match
36-
//~^ HELP try
37-
Some(y) => {
38-
println!("{:?}", y);
39-
}
37+
match x {
38+
//~^ ERROR you seem to be trying to use match
39+
//~| HELP try
40+
//~| SUGGESTION if let Some(y) = x { println!("{:?}", y); };
41+
Some(y) => { println!("{:?}", y); }
4042
_ => ()
41-
}
43+
};
4244

4345
let z = (1u8,1u8);
44-
match z { //~ ERROR you seem to be trying to use match
45-
//~^ HELP try
46-
(2...3, 7...9) => println!("{:?}", z),
46+
match z {
47+
//~^ ERROR you seem to be trying to use match
48+
//~| HELP try
49+
//~| SUGGESTION if let (2...3, 7...9) = z { dummy() };
50+
(2...3, 7...9) => dummy(),
4751
_ => {}
48-
}
52+
};
4953

5054
// Not linted (pattern guards used)
5155
match x {
@@ -64,25 +68,31 @@ fn single_match_know_enum() {
6468
let x = Some(1u8);
6569
let y : Result<_, i8> = Ok(1i8);
6670

67-
match x { //~ ERROR you seem to be trying to use match
68-
//~^ HELP try
69-
Some(y) => println!("{:?}", y),
71+
match x {
72+
//~^ ERROR you seem to be trying to use match
73+
//~| HELP try
74+
//~| SUGGESTION if let Some(y) = x { dummy() };
75+
Some(y) => dummy(),
7076
None => ()
71-
}
77+
};
7278

73-
match y { //~ ERROR you seem to be trying to use match
74-
//~^ HELP try
75-
Ok(y) => println!("{:?}", y),
79+
match y {
80+
//~^ ERROR you seem to be trying to use match
81+
//~| HELP try
82+
//~| SUGGESTION if let Ok(y) = y { dummy() };
83+
Ok(y) => dummy(),
7684
Err(..) => ()
77-
}
85+
};
7886

7987
let c = Cow::Borrowed("");
8088

81-
match c { //~ ERROR you seem to be trying to use match
82-
//~^ HELP try
83-
Cow::Borrowed(..) => println!("42"),
89+
match c {
90+
//~^ ERROR you seem to be trying to use match
91+
//~| HELP try
92+
//~| SUGGESTION if let Cow::Borrowed(..) = c { dummy() };
93+
Cow::Borrowed(..) => dummy(),
8494
Cow::Owned(..) => (),
85-
}
95+
};
8696

8797
let z = Foo::Bar;
8898
// no warning
@@ -209,19 +219,19 @@ fn overlapping() {
209219

210220
match 42 {
211221
0 ... 10 => println!("0 ... 10"), //~ERROR: some ranges overlap
212-
0 ... 11 => println!("0 ... 10"),
222+
0 ... 11 => println!("0 ... 10"), //~NOTE overlaps with this
213223
_ => (),
214224
}
215225

216226
match 42 {
217227
0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap
218228
6 ... 7 => println!("6 ... 7"),
219-
FOO ... 11 => println!("0 ... 10"),
229+
FOO ... 11 => println!("0 ... 10"), //~NOTE overlaps with this
220230
_ => (),
221231
}
222232

223233
match 42 {
224-
2 => println!("2"),
234+
2 => println!("2"), //~NOTE overlaps with this
225235
0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap
226236
_ => (),
227237
}

0 commit comments

Comments
 (0)