Fix verbose_bit_mask off by one error

Fixes #1940
This commit is contained in:
Mateusz Mikula 2017-08-13 15:13:13 +02:00
parent d6fc34fd08
commit 0d244d3f39
No known key found for this signature in database
GPG Key ID: DEDB213D66933040
3 changed files with 5 additions and 5 deletions

View File

@ -126,7 +126,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
"bit mask could be simplified with a call to `trailing_zeros`",
|db| {
let sugg = Sugg::hir(cx, left1, "...").maybe_par();
db.span_suggestion(e.span, "try", format!("{}.trailing_zeros() > {}", sugg, n.count_ones()));
db.span_suggestion(e.span, "try", format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()));
});
}}
}

View File

@ -10,7 +10,7 @@ error: bit mask could be simplified with a call to `trailing_zeros`
--> $DIR/bit_masks.rs:12:5
|
12 | x & 0 == 0;
| ^^^^^^^^^^ help: try: `x.trailing_zeros() > 0`
| ^^^^^^^^^^ help: try: `x.trailing_zeros() >= 0`
|
= note: `-D verbose-bit-mask` implied by `-D warnings`
@ -18,7 +18,7 @@ error: bit mask could be simplified with a call to `trailing_zeros`
--> $DIR/bit_masks.rs:14:5
|
14 | x & 1 == 0; //ok, compared with zero
| ^^^^^^^^^^ help: try: `x.trailing_zeros() > 1`
| ^^^^^^^^^^ help: try: `x.trailing_zeros() >= 1`
error: incompatible bit mask: `_ & 2` can never be equal to `1`
--> $DIR/bit_masks.rs:15:5

View File

@ -2,7 +2,7 @@ error: bit mask could be simplified with a call to `trailing_zeros`
--> $DIR/trailing_zeros.rs:7:31
|
7 | let _ = #[clippy(author)] (x & 0b1111 == 0); // suggest trailing_zeros
| ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() > 4`
| ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 4`
|
= note: `-D verbose-bit-mask` implied by `-D warnings`
@ -10,7 +10,7 @@ error: bit mask could be simplified with a call to `trailing_zeros`
--> $DIR/trailing_zeros.rs:8:13
|
8 | let _ = x & 0b1_1111 == 0; // suggest trailing_zeros
| ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() > 5`
| ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 5`
error: aborting due to 2 previous errors