step_by(0) always panics
ID |
rust.correctness.calls_step_panic |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Api Misuse |
Language |
Rust |
Description
Iterator::step_by panics when the step is zero, so this call aborts the thread every time it runs. Pass a step of at least one, or check the value before building the iterator.
Rationale
Iterator::step_by panics when the step is zero, so this call aborts the thread every time it runs. Pass a step of at least one, or check the value before building the iterator.
The following code illustrates the pattern detected by this rule:
pub fn ranges() {
// FLAGGED: `step_by(0)` always panics
for i in (0..10).step_by(0) {
println!("{}", i);
}
}