Compare commits
2 Commits
master
...
rule/S2437
Author | SHA1 | Date | |
---|---|---|---|
![]() |
35b20f35fd | ||
![]() |
05a2bd0cdf |
6
rules/S2437/rust/metadata.json
Normal file
6
rules/S2437/rust/metadata.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"tags": [
|
||||
"suspicious",
|
||||
"clippy"
|
||||
]
|
||||
}
|
28
rules/S2437/rust/rule.adoc
Normal file
28
rules/S2437/rust/rule.adoc
Normal file
@ -0,0 +1,28 @@
|
||||
== Why is this an issue?
|
||||
|
||||
Using redundant bit masks in comparisons can be misleading because the bit mask does not alter the result of the comparison. This makes the code harder to read and understand. It may also suggest incorrect logic or purpose, increasing the risk of errors.
|
||||
|
||||
=== Code examples
|
||||
|
||||
==== Noncompliant code example
|
||||
|
||||
[source,rust,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
let x = 1;
|
||||
if (x | 2 > 3) { // Noncompliant: Bitwise OR with 1 is redundant in this context
|
||||
}
|
||||
----
|
||||
|
||||
==== Compliant solution
|
||||
|
||||
[source,rust,diff-id=1,diff-type=compliant]
|
||||
----
|
||||
let x = 1;
|
||||
if (x > 3) { // Compliant: Simplifies the comparison by removing redundant bit operation
|
||||
}
|
||||
----
|
||||
|
||||
== Resources
|
||||
=== Documentation
|
||||
|
||||
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#ineffective_bit_mask
|
Loading…
x
Reference in New Issue
Block a user