29 lines
809 B
Plaintext
29 lines
809 B
Plaintext
![]() |
== Why is this an issue?
|
||
|
|
||
|
Getting the remainder of an integer division by one always results in zero, making the operation redundant. Using minus one as the divisor can cause panic or overflow issues.
|
||
|
|
||
|
=== Code examples
|
||
|
|
||
|
==== Noncompliant code example
|
||
|
|
||
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
||
|
----
|
||
|
let x = 1;
|
||
|
let a = x % 1; // Noncompliant: Remainder of division by one.
|
||
|
let b = x % -1; // Noncompliant: Remainder of division by minus one.
|
||
|
----
|
||
|
|
||
|
==== Compliant solution
|
||
|
|
||
|
[source,rust,diff-id=1,diff-type=compliant]
|
||
|
----
|
||
|
let x = 1;
|
||
|
let a = 0; // Compliant: Directly assigning zero instead of using `% 1`.
|
||
|
let b = 0; // Compliant: Directly assigning zero instead of using `% -1`.
|
||
|
----
|
||
|
|
||
|
== Resources
|
||
|
=== Documentation
|
||
|
|
||
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#modulo_one
|