29 lines
743 B
Plaintext
29 lines
743 B
Plaintext
|
|
== Why is this an issue?
|
|
Calling `.step_by(0)` on an iterator will cause the program to panic. This is likely an oversight and should be corrected to ensure program stability. If the intent is to cause a panic, it is clearer to use `panic!()` directly.
|
|
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
for x in (0..100).step_by(0) { // Noncompliant: This will cause a panic.
|
|
// ...
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,rust,diff-id=1,diff-type=compliant]
|
|
----
|
|
for x in (0..100).step_by(1) { // Compliant: Step by a valid positive integer.
|
|
// ...
|
|
}
|
|
----
|
|
|
|
== Resources
|
|
=== Documentation
|
|
|
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#iterator_step_by_zero
|