Update RSPEC

This commit is contained in:
yassin-kammoun-sonarsource 2025-03-25 13:49:04 +01:00
parent 2e607bb4cb
commit 2260648cc8
2 changed files with 14 additions and 27 deletions

View File

@ -1,2 +1,7 @@
{
}
"title": "Erasing mathematical operations should not be performed",
"tags": [
"clumsy",
"clippy"
]
}

View File

@ -1,16 +1,6 @@
FIXME: add a description
// If you want to factorize the description uncomment the following line and create the file.
//include::../description.adoc[]
== Why is this an issue?
FIXME: remove the unused optional headers (that are commented out)
//=== What is the potential impact?
== How to fix it
//== How to fix it in FRAMEWORK NAME
Erasing operations (e.g., any operation involving multiplying by zero, dividing zero by a value, or bitwise AND with zero) always result in zero regardless of the operands, which makes the expression unnecessary and can be replaced directly with zero. This simplifies the code and avoids potential confusion about the intent of the expression.
=== Code examples
@ -18,27 +8,19 @@ FIXME: remove the unused optional headers (that are commented out)
[source,rust,diff-id=1,diff-type=noncompliant]
----
FIXME
let x = 1;
let result = 0 * x; // Noncompliant: Result is always zero.
----
==== Compliant solution
[source,rust,diff-id=1,diff-type=compliant]
----
FIXME
let x = 1;
let result = 0; // Compliant: Simplified expression.
----
//=== How does this work?
== Resources
=== Documentation
//=== Pitfalls
//=== Going the extra mile
//== Resources
//=== Documentation
//=== Articles & blog posts
//=== Conference presentations
//=== Standards
//=== External coding guidelines
//=== Benchmarks
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#erasing_op