2015-04-30 09:48:43 +00:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
|
2015-04-30 13:17:06 +00:00
|
|
|
const THREE_BITS : i64 = 7;
|
|
|
|
const EVEN_MORE_REDIRECTION : i64 = THREE_BITS;
|
|
|
|
|
|
|
|
#[deny(bad_bit_mask)]
|
2015-04-30 09:48:43 +00:00
|
|
|
fn main() {
|
|
|
|
let x = 5;
|
2015-05-04 05:17:15 +00:00
|
|
|
|
|
|
|
x & 0 == 0; //~ERROR &-masking with zero
|
2015-04-30 09:48:43 +00:00
|
|
|
x & 1 == 1; //ok, distinguishes bit 0
|
|
|
|
x & 2 == 1; //~ERROR
|
2015-05-04 05:17:15 +00:00
|
|
|
x | 0 == 0; //ok, equals x == 0 (maybe warn?)
|
2015-04-30 09:48:43 +00:00
|
|
|
x | 1 == 3; //ok, equals x == 2 || x == 3
|
|
|
|
x | 3 == 3; //ok, equals x <= 3
|
|
|
|
x | 3 == 2; //~ERROR
|
2015-05-04 05:17:15 +00:00
|
|
|
|
2015-04-30 09:48:43 +00:00
|
|
|
x & 1 > 1; //~ERROR
|
|
|
|
x & 2 > 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0
|
|
|
|
x & 2 < 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0
|
|
|
|
x | 1 > 1; // ok (if a bit silly), equals x > 1
|
|
|
|
x | 2 > 1; //~ERROR
|
|
|
|
x | 2 <= 2; // ok (if a bit silly), equals x <= 2
|
2015-04-30 13:17:06 +00:00
|
|
|
|
|
|
|
// this also now works with constants
|
|
|
|
x & THREE_BITS == 8; //~ERROR
|
|
|
|
x | EVEN_MORE_REDIRECTION < 7; //~ERROR
|
2015-05-04 05:17:15 +00:00
|
|
|
|
|
|
|
0 & x == 0; //~ERROR
|
|
|
|
1 | x > 1;
|
|
|
|
|
|
|
|
// and should now also match uncommon usage
|
|
|
|
1 < 2 | x; //~ERROR
|
|
|
|
2 == 3 | x; //~ERROR
|
|
|
|
1 == x & 2; //~ERROR
|
2015-04-30 09:48:43 +00:00
|
|
|
}
|