]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/match_bool.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / match_bool.rs
1 //@no-rustfix: overlapping suggestions
2 #![deny(clippy::match_bool)]
3
4 fn match_bool() {
5 let test: bool = true;
6
7 match test {
8 //~^ ERROR: you seem to be trying to match on a boolean expression
9 true => 0,
10 false => 42,
11 };
12
13 let option = 1;
14 match option == 1 {
15 //~^ ERROR: you seem to be trying to match on a boolean expression
16 true => 1,
17 false => 0,
18 };
19
20 match test {
21 //~^ ERROR: you seem to be trying to match on a boolean expression
22 true => (),
23 false => {
24 println!("Noooo!");
25 },
26 };
27
28 match test {
29 //~^ ERROR: you seem to be trying to match on a boolean expression
30 false => {
31 println!("Noooo!");
32 },
33 _ => (),
34 };
35
36 match test && test {
37 //~^ ERROR: this boolean expression can be simplified
38 //~| NOTE: `-D clippy::nonminimal-bool` implied by `-D warnings`
39 //~| ERROR: you seem to be trying to match on a boolean expression
40 //~| ERROR: equal expressions as operands to `&&`
41 //~| NOTE: `#[deny(clippy::eq_op)]` on by default
42 false => {
43 println!("Noooo!");
44 },
45 _ => (),
46 };
47
48 match test {
49 //~^ ERROR: you seem to be trying to match on a boolean expression
50 false => {
51 println!("Noooo!");
52 },
53 true => {
54 println!("Yes!");
55 },
56 };
57
58 // Not linted
59 match option {
60 1..=10 => 1,
61 11..=20 => 2,
62 _ => 3,
63 };
64
65 // Don't lint
66 let _ = match test {
67 #[cfg(feature = "foo")]
68 true if option == 5 => 10,
69 true => 0,
70 false => 1,
71 };
72 }
73
74 fn main() {}