]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/booleans.rs
Add environment variable to deactivate wiki links
[rust.git] / tests / compile-fail / booleans.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3 #![deny(nonminimal_bool, logic_bug)]
4
5 #[allow(unused, many_single_char_names)]
6 fn main() {
7     let a: bool = unimplemented!();
8     let b: bool = unimplemented!();
9     let c: bool = unimplemented!();
10     let d: bool = unimplemented!();
11     let e: bool = unimplemented!();
12     let _ = a && b || a; //~ ERROR this boolean expression contains a logic bug
13     //~| HELP this expression can be optimized out
14     //~| HELP it would look like the following
15     //~| SUGGESTION let _ = a;
16     let _ = !(a && b);
17     let _ = !true; //~ ERROR this boolean expression can be simplified
18     //~| HELP try
19     //~| SUGGESTION let _ = false;
20     let _ = !false; //~ ERROR this boolean expression can be simplified
21     //~| HELP try
22     //~| SUGGESTION let _ = true;
23     let _ = !!a; //~ ERROR this boolean expression can be simplified
24     //~| HELP try
25     //~| SUGGESTION let _ = a;
26
27     let _ = false && a; //~ ERROR this boolean expression contains a logic bug
28     //~| HELP this expression can be optimized out
29     //~| HELP it would look like the following
30     //~| SUGGESTION let _ = false;
31
32     let _ = false || a; //~ ERROR this boolean expression can be simplified
33     //~| HELP try
34     //~| SUGGESTION let _ = a;
35
36     // don't lint on cfgs
37     let _ = cfg!(you_shall_not_not_pass) && a;
38
39     let _ = a || !b || !c || !d || !e;
40
41     let _ = !(a && b || c);
42
43     let _ = !(!a && b); //~ ERROR this boolean expression can be simplified
44     //~| HELP try
45     //~| SUGGESTION let _ = !b || a;
46 }
47
48 #[allow(unused, many_single_char_names)]
49 fn equality_stuff() {
50     let a: i32 = unimplemented!();
51     let b: i32 = unimplemented!();
52     let c: i32 = unimplemented!();
53     let d: i32 = unimplemented!();
54     let e: i32 = unimplemented!();
55     let _ = a == b && a != b; //~ ERROR this boolean expression contains a logic bug
56     //~| HELP this expression can be optimized out
57     //~| HELP it would look like the following
58     //~| SUGGESTION let _ = false;
59     let _ = a == b && c == 5 && a == b; //~ ERROR this boolean expression can be simplified
60     //~| HELP try
61     //~| SUGGESTION let _ = a == b && c == 5;
62     let _ = a == b && c == 5 && b == a; //~ ERROR this boolean expression can be simplified
63     //~| HELP try
64     //~| SUGGESTION let _ = a == b && c == 5;
65     //~| HELP try
66     //~| SUGGESTION let _ = !(c != 5 || a != b);
67     let _ = a < b && a >= b; //~ ERROR this boolean expression contains a logic bug
68     //~| HELP this expression can be optimized out
69     //~| HELP it would look like the following
70     //~| SUGGESTION let _ = false;
71     let _ = a > b && a <= b; //~ ERROR this boolean expression contains a logic bug
72     //~| HELP this expression can be optimized out
73     //~| HELP it would look like the following
74     //~| SUGGESTION let _ = false;
75     let _ = a > b && a == b;
76
77     let _ = a != b || !(a != b || c == d); //~ ERROR this boolean expression can be simplified
78     //~| HELP try
79     //~| SUGGESTION let _ = c != d || a != b;
80     //~| HELP try
81     //~| SUGGESTION let _ = !(a == b && c == d);
82 }