1 const THREE_BITS: i64 = 7;
2 const EVEN_MORE_REDIRECTION: i64 = THREE_BITS;
3 
4 #[warn(clippy::bad_bit_mask)]
5 #[allow(
6     clippy::ineffective_bit_mask,
7     clippy::identity_op,
8     clippy::no_effect,
9     clippy::unnecessary_operation
10 )]
main()11 fn main() {
12     let x = 5;
13 
14     x & 0 == 0;
15     x & 1 == 1; //ok, distinguishes bit 0
16     x & 1 == 0; //ok, compared with zero
17     x & 2 == 1;
18     x | 0 == 0; //ok, equals x == 0 (maybe warn?)
19     x | 1 == 3; //ok, equals x == 2 || x == 3
20     x | 3 == 3; //ok, equals x <= 3
21     x | 3 == 2;
22 
23     x & 1 > 1;
24     x & 2 > 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0
25     x & 2 < 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0
26     x | 1 > 1; // ok (if a bit silly), equals x > 1
27     x | 2 > 1;
28     x | 2 <= 2; // ok (if a bit silly), equals x <= 2
29 
30     x & 192 == 128; // ok, tests for bit 7 and not bit 6
31     x & 0xffc0 == 0xfe80; // ok
32 
33     // this also now works with constants
34     x & THREE_BITS == 8;
35     x | EVEN_MORE_REDIRECTION < 7;
36 
37     0 & x == 0;
38     1 | x > 1;
39 
40     // and should now also match uncommon usage
41     1 < 2 | x;
42     2 == 3 | x;
43     1 == x & 2;
44 
45     x | 1 > 2; // no error, because we allowed ineffective bit masks
46     ineffective();
47 }
48 
49 #[warn(clippy::ineffective_bit_mask)]
50 #[allow(clippy::bad_bit_mask, clippy::no_effect, clippy::unnecessary_operation)]
ineffective()51 fn ineffective() {
52     let x = 5;
53 
54     x | 1 > 3;
55     x | 1 < 4;
56     x | 1 <= 3;
57     x | 1 >= 8;
58 
59     x | 1 > 2; // not an error (yet), better written as x >= 2
60     x | 1 >= 7; // not an error (yet), better written as x >= 6
61     x | 3 > 4; // not an error (yet), better written as x >= 4
62     x | 4 <= 19;
63 }
64