Skip to content

Commit 1ce5ec8

Browse files
authored
Merge pull request #2643 from phansch/split_up_match_bool_ui_tests
Split up match_bool UI tests
2 parents fbb5050 + 5abe348 commit 1ce5ec8

File tree

4 files changed

+271
-267
lines changed

4 files changed

+271
-267
lines changed

tests/ui/match_bool.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
fn match_bool() {
2+
let test: bool = true;
3+
4+
match test {
5+
true => 0,
6+
false => 42,
7+
};
8+
9+
let option = 1;
10+
match option == 1 {
11+
true => 1,
12+
false => 0,
13+
};
14+
15+
match test {
16+
true => (),
17+
false => { println!("Noooo!"); }
18+
};
19+
20+
match test {
21+
false => { println!("Noooo!"); }
22+
_ => (),
23+
};
24+
25+
match test && test {
26+
false => { println!("Noooo!"); }
27+
_ => (),
28+
};
29+
30+
match test {
31+
false => { println!("Noooo!"); }
32+
true => { println!("Yes!"); }
33+
};
34+
35+
// Not linted
36+
match option {
37+
1 ... 10 => 1,
38+
11 ... 20 => 2,
39+
_ => 3,
40+
};
41+
}
42+
43+
fn main() {
44+
}

tests/ui/match_bool.stderr

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
error: this boolean expression can be simplified
2+
--> $DIR/match_bool.rs:25:11
3+
|
4+
25 | match test && test {
5+
| ^^^^^^^^^^^^ help: try: `test`
6+
|
7+
= note: `-D nonminimal-bool` implied by `-D warnings`
8+
9+
error: you seem to be trying to match on a boolean expression
10+
--> $DIR/match_bool.rs:4:5
11+
|
12+
4 | / match test {
13+
5 | | true => 0,
14+
6 | | false => 42,
15+
7 | | };
16+
| |_____^ help: consider using an if/else expression: `if test { 0 } else { 42 }`
17+
|
18+
= note: `-D match-bool` implied by `-D warnings`
19+
20+
error: you seem to be trying to match on a boolean expression
21+
--> $DIR/match_bool.rs:10:5
22+
|
23+
10 | / match option == 1 {
24+
11 | | true => 1,
25+
12 | | false => 0,
26+
13 | | };
27+
| |_____^ help: consider using an if/else expression: `if option == 1 { 1 } else { 0 }`
28+
29+
error: you seem to be trying to match on a boolean expression
30+
--> $DIR/match_bool.rs:15:5
31+
|
32+
15 | / match test {
33+
16 | | true => (),
34+
17 | | false => { println!("Noooo!"); }
35+
18 | | };
36+
| |_____^ help: consider using an if/else expression: `if !test { println!("Noooo!"); }`
37+
38+
error: you seem to be trying to match on a boolean expression
39+
--> $DIR/match_bool.rs:20:5
40+
|
41+
20 | / match test {
42+
21 | | false => { println!("Noooo!"); }
43+
22 | | _ => (),
44+
23 | | };
45+
| |_____^ help: consider using an if/else expression: `if !test { println!("Noooo!"); }`
46+
47+
error: you seem to be trying to match on a boolean expression
48+
--> $DIR/match_bool.rs:25:5
49+
|
50+
25 | / match test && test {
51+
26 | | false => { println!("Noooo!"); }
52+
27 | | _ => (),
53+
28 | | };
54+
| |_____^ help: consider using an if/else expression: `if !(test && test) { println!("Noooo!"); }`
55+
56+
error: equal expressions as operands to `&&`
57+
--> $DIR/match_bool.rs:25:11
58+
|
59+
25 | match test && test {
60+
| ^^^^^^^^^^^^
61+
|
62+
= note: #[deny(eq_op)] on by default
63+
64+
error: you seem to be trying to match on a boolean expression
65+
--> $DIR/match_bool.rs:30:5
66+
|
67+
30 | / match test {
68+
31 | | false => { println!("Noooo!"); }
69+
32 | | true => { println!("Yes!"); }
70+
33 | | };
71+
| |_____^ help: consider using an if/else expression: `if test { println!("Yes!"); } else { println!("Noooo!"); }`
72+
73+
error: aborting due to 8 previous errors
74+

tests/ui/matches.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,6 @@ fn unwrap_addr() -> Option<&'static ExprNode> {
2424
}
2525
}
2626

27-
fn match_bool() {
28-
let test: bool = true;
29-
30-
match test {
31-
true => 0,
32-
false => 42,
33-
};
34-
35-
let option = 1;
36-
match option == 1 {
37-
true => 1,
38-
false => 0,
39-
};
40-
41-
match test {
42-
true => (),
43-
false => { println!("Noooo!"); }
44-
};
45-
46-
match test {
47-
false => { println!("Noooo!"); }
48-
_ => (),
49-
};
50-
51-
match test && test {
52-
false => { println!("Noooo!"); }
53-
_ => (),
54-
};
55-
56-
match test {
57-
false => { println!("Noooo!"); }
58-
true => { println!("Yes!"); }
59-
};
60-
61-
// Not linted
62-
match option {
63-
1 ... 10 => 1,
64-
11 ... 20 => 2,
65-
_ => 3,
66-
};
67-
}
68-
6927
fn ref_pats() {
7028
{
7129
let v = &Some(0);

0 commit comments

Comments
 (0)