Skip to content

Commit 3ab06c1

Browse files
authored
Merge pull request #1953 from mati865/master
Fix verbose_bit_mask off by one error
2 parents d6fc34f + 0d244d3 commit 3ab06c1

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

clippy_lints/src/bit_mask.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
126126
"bit mask could be simplified with a call to `trailing_zeros`",
127127
|db| {
128128
let sugg = Sugg::hir(cx, left1, "...").maybe_par();
129-
db.span_suggestion(e.span, "try", format!("{}.trailing_zeros() > {}", sugg, n.count_ones()));
129+
db.span_suggestion(e.span, "try", format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()));
130130
});
131131
}}
132132
}

tests/ui/bit_masks.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ error: bit mask could be simplified with a call to `trailing_zeros`
1010
--> $DIR/bit_masks.rs:12:5
1111
|
1212
12 | x & 0 == 0;
13-
| ^^^^^^^^^^ help: try: `x.trailing_zeros() > 0`
13+
| ^^^^^^^^^^ help: try: `x.trailing_zeros() >= 0`
1414
|
1515
= note: `-D verbose-bit-mask` implied by `-D warnings`
1616

1717
error: bit mask could be simplified with a call to `trailing_zeros`
1818
--> $DIR/bit_masks.rs:14:5
1919
|
2020
14 | x & 1 == 0; //ok, compared with zero
21-
| ^^^^^^^^^^ help: try: `x.trailing_zeros() > 1`
21+
| ^^^^^^^^^^ help: try: `x.trailing_zeros() >= 1`
2222

2323
error: incompatible bit mask: `_ & 2` can never be equal to `1`
2424
--> $DIR/bit_masks.rs:15:5

tests/ui/trailing_zeros.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ error: bit mask could be simplified with a call to `trailing_zeros`
22
--> $DIR/trailing_zeros.rs:7:31
33
|
44
7 | let _ = #[clippy(author)] (x & 0b1111 == 0); // suggest trailing_zeros
5-
| ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() > 4`
5+
| ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 4`
66
|
77
= note: `-D verbose-bit-mask` implied by `-D warnings`
88

99
error: bit mask could be simplified with a call to `trailing_zeros`
1010
--> $DIR/trailing_zeros.rs:8:13
1111
|
1212
8 | let _ = x & 0b1_1111 == 0; // suggest trailing_zeros
13-
| ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() > 5`
13+
| ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 5`
1414

1515
error: aborting due to 2 previous errors
1616

0 commit comments

Comments
 (0)