]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/absurd-extreme-comparisons.rs
Fix deploy.sh III
[rust.git] / tests / compile-fail / absurd-extreme-comparisons.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #![deny(absurd_extreme_comparisons)]
5 #![allow(unused, eq_op, no_effect, unnecessary_operation)]
6 fn main() {
7     const Z: u32 = 0;
8
9     let u: u32 = 42;
10
11     u <= 0;
12     //~^ ERROR this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
13     //~| HELP using u == 0 instead
14     u <= Z;
15     //~^ ERROR this comparison involving
16     //~| HELP using u == Z instead
17     u < Z;
18     //~^ ERROR this comparison involving
19     //~| HELP comparison is always false
20     Z >= u;
21     //~^ ERROR this comparison involving
22     //~| HELP using Z == u instead
23     Z > u;
24     //~^ ERROR this comparison involving
25     //~| HELP comparison is always false
26     u > std::u32::MAX;
27     //~^ ERROR this comparison involving
28     //~| HELP comparison is always false
29     u >= std::u32::MAX;
30     //~^ ERROR this comparison involving
31     //~| HELP using u == std::u32::MAX instead
32     std::u32::MAX < u;
33     //~^ ERROR this comparison involving
34     //~| HELP comparison is always false
35     std::u32::MAX <= u;
36     //~^ ERROR this comparison involving
37     //~| HELP using std::u32::MAX == u instead
38
39     1-1 > u;
40         //~^ ERROR this comparison involving
41         //~| HELP because 1-1 is the minimum value for this type, this comparison is always false
42     u >= !0;
43         //~^ ERROR this comparison involving
44         //~| HELP because !0 is the maximum value for this type, the case where the two sides are not equal never occurs, consider using u == !0 instead
45     u <= 12 - 2*6;
46         //~^ ERROR this comparison involving
47         //~| HELP because 12 - 2*6 is the minimum value for this type, the case where the two sides are not equal never occurs, consider using u == 12 - 2*6 instead
48
49     let i: i8 = 0;
50     i < -127 - 1;
51     //~^ ERROR this comparison involving
52     //~| HELP comparison is always false
53     std::i8::MAX >= i;
54     //~^ ERROR this comparison involving
55     //~| HELP comparison is always true
56     3-7 < std::i32::MIN;
57     //~^ ERROR this comparison involving
58     //~| HELP comparison is always false
59
60     let b = false;
61     b >= true;
62     //~^ ERROR this comparison involving
63     //~| HELP using b == true instead
64     false > b;
65     //~^ ERROR this comparison involving
66     //~| HELP comparison is always false
67
68     u > 0; // ok
69
70     // this is handled by unit_cmp
71     () < {}; //~WARNING <-comparison of unit values detected.
72 }