mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-08 09:38:26 +03:00
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`
}
```
This commit is contained in:
@@ -262,7 +262,7 @@
|
||||
/// 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 @@
|
||||
///
|
||||
/// ```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,
|
||||
|
||||
Reference in New Issue
Block a user