]> git.lizzy.rs Git - rust.git/blob - tests/ui/invalid_upcast_comparisons.rs
rustup and compile-fail -> ui test move
[rust.git] / tests / ui / invalid_upcast_comparisons.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #![deny(invalid_upcast_comparisons)]
5 #![allow(unused, eq_op, no_effect, unnecessary_operation)]
6 fn main() {
7     let zero: u32 = 0;
8     let u8_max: u8 = 255;
9
10     (u8_max as u32) > 300; //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always false
11     (u8_max as u32) > 20;
12
13     (zero as i32) < -5; //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always false
14     (zero as i32) < 10;
15
16     -5 < (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always true
17     0 <= (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always true
18     0 < (zero as i32);
19
20     -5 > (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always false
21     -5 >= (u8_max as i32); //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always false
22     1337 == (u8_max as i32); //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always false
23
24     -5 == (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always false
25     -5 != (u8_max as i32); //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always true
26
27     // Those are Ok:
28     42 == (u8_max as i32);
29     42 != (u8_max as i32);
30     42 > (u8_max as i32);
31     (u8_max as i32) == 42;
32     (u8_max as i32) != 42;
33     (u8_max as i32) > 42;
34     (u8_max as i32) < 42;
35 }