diff --git a/README.md b/README.md index c7071688e10..0da19cbd620 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ There are 55 lints included in this crate: name | default | meaning -----------------------------------------------------------------------------------------------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- [approx_constant](https://github.com/Manishearth/rust-clippy/wiki#approx_constant) | warn | the approximate of a known float constant (in `std::f64::consts` or `std::f32::consts`) is found; suggests to use the constant -[bad_bit_mask](https://github.com/Manishearth/rust-clippy/wiki#bad_bit_mask) | deny | expressions of the form `_ & mask == select` that will only ever return `true` or `false` (because in the example `select` containing bits that `mask` doesn't have) +[bad_bit_mask](https://github.com/Manishearth/rust-clippy/wiki#bad_bit_mask) | warn | expressions of the form `_ & mask == select` that will only ever return `true` or `false` (because in the example `select` containing bits that `mask` doesn't have) [box_vec](https://github.com/Manishearth/rust-clippy/wiki#box_vec) | warn | usage of `Box<Vec<T>>`, vector elements are already on the heap [cast_possible_truncation](https://github.com/Manishearth/rust-clippy/wiki#cast_possible_truncation) | allow | casts that may cause truncation of the value, e.g `x as u8` where `x: u32`, or `x as i32` where `x: f32` [cast_possible_wrap](https://github.com/Manishearth/rust-clippy/wiki#cast_possible_wrap) | allow | casts that may cause wrapping around the value, e.g `x as i32` where `x: u32` and `x > i32::MAX` diff --git a/src/bit_mask.rs b/src/bit_mask.rs index b1b8a735455..97d33b5e699 100644 --- a/src/bit_mask.rs +++ b/src/bit_mask.rs @@ -9,7 +9,7 @@ use utils::span_lint; declare_lint! { pub BAD_BIT_MASK, - Deny, + Warn, "expressions of the form `_ & mask == select` that will only ever return `true` or `false` \ (because in the example `select` containing bits that `mask` doesn't have)" } @@ -98,7 +98,7 @@ fn check_bit_mask(cx: &Context, bit_op: BinOp_, cmp_op: BinOp_, mask_value: u64, cmp_value: u64, span: &Span) { match cmp_op { BiEq | BiNe => match bit_op { - BiBitAnd => if mask_value & cmp_value != mask_value { + BiBitAnd => if mask_value & cmp_value != cmp_value { if cmp_value != 0 { span_lint(cx, BAD_BIT_MASK, *span, &format!( "incompatible bit mask: `_ & {}` can never be equal to `{}`", diff --git a/tests/compile-fail/bit_masks.rs b/tests/compile-fail/bit_masks.rs index 47e9c11138a..0b7b31b64a5 100755 --- a/tests/compile-fail/bit_masks.rs +++ b/tests/compile-fail/bit_masks.rs @@ -25,6 +25,9 @@ fn main() { x | 2 > 1; //~ERROR incompatible bit mask x | 2 <= 2; // ok (if a bit silly), equals x <= 2 + x & 192 == 128; // ok, tests for bit 7 and not bit 6 + x & 0xffc0 == 0xfe80; // ok + // this also now works with constants x & THREE_BITS == 8; //~ERROR incompatible bit mask x | EVEN_MORE_REDIRECTION < 7; //~ERROR incompatible bit mask