about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Wong <joshuawong@anticentri.st>2025-01-21 19:50:48 -0500
committerJoshua Wong <joshuawong@anticentri.st>2025-01-21 19:50:48 -0500
commita18b75a87ed29a074cb751c840ccff65cbd12815 (patch)
tree3ba10d1ec46b6c607dba2bedd56f2b3b7c20d06e
parentd1b5fa2416f48abc4e5f54df040a3aed864c88cf (diff)
downloadrust-a18b75a87ed29a074cb751c840ccff65cbd12815.tar.gz
rust-a18b75a87ed29a074cb751c840ccff65cbd12815.zip
docs: fix verbose-bit-mask example
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`
}
```
-rw-r--r--clippy_lints/src/operators/mod.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/clippy_lints/src/operators/mod.rs b/clippy_lints/src/operators/mod.rs
index 9e8a821c3f4..d9845bc3b0f 100644
--- a/clippy_lints/src/operators/mod.rs
+++ b/clippy_lints/src/operators/mod.rs
@@ -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
@@ -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,