]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/absurd-extreme-comparisons.rs
7e2ad1fede5469c2f78028de6e74e6ebdc2b62a5
[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)]
6 fn main() {
7     const Z: u32 = 0;
8
9     let u: u32 = 42;
10
11     u <= 0; //~ERROR this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
12     u <= Z; //~ERROR this comparison involving
13     u < Z; //~ERROR this comparison involving
14     Z >= u; //~ERROR this comparison involving
15     Z > u; //~ERROR this comparison involving
16     u > std::u32::MAX; //~ERROR this comparison involving
17     u >= std::u32::MAX; //~ERROR this comparison involving
18     std::u32::MAX < u; //~ERROR this comparison involving
19     std::u32::MAX <= u; //~ERROR this comparison involving
20
21     1-1 > u;
22         //~^ ERROR this comparison involving
23         //~| HELP because 1-1 is the minimum value for this type, this comparison is always false
24     u >= !0;
25         //~^ ERROR this comparison involving
26         //~| 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
27     u <= 12 - 2*6;
28         //~^ ERROR this comparison involving
29         //~| 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
30
31     let i: i8 = 0;
32     i < -127 - 1; //~ERROR this comparison involving
33     std::i8::MAX >= i; //~ERROR this comparison involving
34     3-7 < std::i32::MIN; //~ERROR this comparison involving
35
36     let b = false;
37     b >= true; //~ERROR this comparison involving
38     false > b; //~ERROR this comparison involving
39
40     u > 0; // ok
41
42     // this is handled by unit_cmp
43     () < {}; //~WARNING <-comparison of unit values detected.
44 }