2016-02-03 03:48:52 +00:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
|
|
|
|
#![deny(absurd_extreme_comparisons)]
|
2016-05-13 14:43:47 +00:00
|
|
|
#![allow(unused, eq_op, no_effect, unnecessary_operation)]
|
2016-12-21 15:49:53 +00:00
|
|
|
|
2016-02-03 03:48:52 +00:00
|
|
|
fn main() {
|
|
|
|
const Z: u32 = 0;
|
|
|
|
|
|
|
|
let u: u32 = 42;
|
|
|
|
|
2016-06-07 16:32:26 +00:00
|
|
|
u <= 0;
|
2016-12-21 11:30:41 +00:00
|
|
|
//~^ ERROR this comparison involving the minimum or maximum element for this type contains a
|
2016-06-07 16:32:26 +00:00
|
|
|
//~| HELP using u == 0 instead
|
|
|
|
u <= Z;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP using u == Z instead
|
|
|
|
u < Z;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP comparison is always false
|
|
|
|
Z >= u;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP using Z == u instead
|
|
|
|
Z > u;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP comparison is always false
|
|
|
|
u > std::u32::MAX;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP comparison is always false
|
|
|
|
u >= std::u32::MAX;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP using u == std::u32::MAX instead
|
|
|
|
std::u32::MAX < u;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP comparison is always false
|
|
|
|
std::u32::MAX <= u;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP using std::u32::MAX == u instead
|
2016-02-03 03:48:52 +00:00
|
|
|
|
|
|
|
1-1 > u;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP because 1-1 is the minimum value for this type, this comparison is always false
|
|
|
|
u >= !0;
|
|
|
|
//~^ ERROR this comparison involving
|
2016-12-21 11:30:41 +00:00
|
|
|
//~| HELP consider using u == !0 instead
|
2016-02-03 03:48:52 +00:00
|
|
|
u <= 12 - 2*6;
|
|
|
|
//~^ ERROR this comparison involving
|
2016-12-21 11:30:41 +00:00
|
|
|
//~| HELP consider using u == 12 - 2*6 instead
|
2016-02-03 03:48:52 +00:00
|
|
|
|
|
|
|
let i: i8 = 0;
|
2016-06-07 16:32:26 +00:00
|
|
|
i < -127 - 1;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP comparison is always false
|
|
|
|
std::i8::MAX >= i;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP comparison is always true
|
|
|
|
3-7 < std::i32::MIN;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP comparison is always false
|
2016-02-03 03:48:52 +00:00
|
|
|
|
|
|
|
let b = false;
|
2016-06-07 16:32:26 +00:00
|
|
|
b >= true;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP using b == true instead
|
|
|
|
false > b;
|
|
|
|
//~^ ERROR this comparison involving
|
|
|
|
//~| HELP comparison is always false
|
2016-02-03 03:48:52 +00:00
|
|
|
|
|
|
|
u > 0; // ok
|
|
|
|
|
|
|
|
// this is handled by unit_cmp
|
|
|
|
() < {}; //~WARNING <-comparison of unit values detected.
|
|
|
|
}
|
2016-12-21 15:49:53 +00:00
|
|
|
|
|
|
|
use std::cmp::{Ordering, PartialEq, PartialOrd};
|
|
|
|
|
|
|
|
#[derive(PartialEq, PartialOrd)]
|
|
|
|
pub struct U(u64);
|
|
|
|
|
|
|
|
impl PartialEq<u32> for U {
|
|
|
|
fn eq(&self, other: &u32) -> bool {
|
|
|
|
self.eq(&U(*other as u64))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl PartialOrd<u32> for U {
|
|
|
|
fn partial_cmp(&self, other: &u32) -> Option<Ordering> {
|
|
|
|
self.partial_cmp(&U(*other as u64))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn foo(val: U) -> bool {
|
|
|
|
val > std::u32::MAX
|
|
|
|
}
|