Add erasing_op lint
For expressions that can be replaced by a zero.
This commit is contained in:
parent
f68e408cb6
commit
033c99b1ba
5 changed files with 110 additions and 0 deletions
|
|
@ -6,6 +6,14 @@ error: &-masking with zero
|
|||
|
|
||||
= note: `-D bad-bit-mask` implied by `-D warnings`
|
||||
|
||||
error: the operation is ineffective. Consider reducing it to `0`
|
||||
--> $DIR/bit_masks.rs:12:5
|
||||
|
|
||||
12 | x & 0 == 0;
|
||||
| ^^^^^
|
||||
|
|
||||
= note: `-D erasing-op` implied by `-D warnings`
|
||||
|
||||
error: incompatible bit mask: `_ & 2` can never be equal to `1`
|
||||
--> $DIR/bit_masks.rs:15:5
|
||||
|
|
||||
|
|
@ -48,6 +56,12 @@ error: &-masking with zero
|
|||
35 | 0 & x == 0;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: the operation is ineffective. Consider reducing it to `0`
|
||||
--> $DIR/bit_masks.rs:35:5
|
||||
|
|
||||
35 | 0 & x == 0;
|
||||
| ^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ | 2` will always be higher than `1`
|
||||
--> $DIR/bit_masks.rs:39:5
|
||||
|
|
||||
|
|
|
|||
12
tests/ui/erasing_op.rs
Normal file
12
tests/ui/erasing_op.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
|
||||
|
||||
#[allow(no_effect)]
|
||||
#[warn(erasing_op)]
|
||||
fn main() {
|
||||
let x: u8 = 0;
|
||||
|
||||
x * 0;
|
||||
0 & x;
|
||||
0 / x;
|
||||
}
|
||||
20
tests/ui/erasing_op.stderr
Normal file
20
tests/ui/erasing_op.stderr
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
error: the operation is ineffective. Consider reducing it to `0`
|
||||
--> $DIR/erasing_op.rs:9:5
|
||||
|
|
||||
9 | x * 0;
|
||||
| ^^^^^
|
||||
|
|
||||
= note: `-D erasing-op` implied by `-D warnings`
|
||||
|
||||
error: the operation is ineffective. Consider reducing it to `0`
|
||||
--> $DIR/erasing_op.rs:10:5
|
||||
|
|
||||
10 | 0 & x;
|
||||
| ^^^^^
|
||||
|
||||
error: the operation is ineffective. Consider reducing it to `0`
|
||||
--> $DIR/erasing_op.rs:11:5
|
||||
|
|
||||
11 | 0 / x;
|
||||
| ^^^^^
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue