Skip to content

Commit

Permalink
docs: fix verbose-bit-mask example (#14055)
Browse files Browse the repository at this point in the history
changelog: none

`x & 15 == 0` is not equivalent to `x.trailing_zeros() > 4`, as `x =
0b10000` is true for the former and false for the latter.

In fact, clippy itself suggests the following:

```rust
pub fn src(x: i32) -> bool {
    x & 15 == 0 // ~error: bit mask could be simplified with a call to `trailing_zeros`
    ^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 4`
}
```
  • Loading branch information
Alexendoo authored Jan 24, 2025
2 parents 4b05f50 + a18b75a commit d7e20a9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/operators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ declare_clippy_lint! {
/// to `trailing_zeros`
///
/// ### Why is this bad?
/// `x.trailing_zeros() > 4` is much clearer than `x & 15
/// `x.trailing_zeros() >= 4` is much clearer than `x & 15
/// == 0`
///
/// ### Known problems
Expand All @@ -278,7 +278,7 @@ declare_clippy_lint! {
///
/// ```no_run
/// # let x: i32 = 1;
/// if x.trailing_zeros() > 4 { }
/// if x.trailing_zeros() >= 4 { }
/// ```
#[clippy::version = "pre 1.29.0"]
pub VERBOSE_BIT_MASK,
Expand Down

0 comments on commit d7e20a9

Please sign in to comment.