Clippy lints / Correctness
Clippy lint · Correctness · checked with Clippy 0.1.99
clippy::iterator_step_by_zero: `Iterator::step_by(0)` will panic at runtime
What it meansChecks for calling .step_by(0) on iterators which panics. It is in the correctness group and denied by default (the build fails).
What you see
error: `Iterator::step_by(0)` will panic at runtime --> main.rs:3:10 | 3 | for x in (0..100).step_by(0) { | ^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/stable/index.html#iterator_step_by_zero = note: `#[deny(clippy::iterator_step_by_zero)]` on by default
Real output of Clippy 0.1.99 (Rust 1.99) on the example below. Names and line numbers in yours will differ.
Does it matter?
This very much looks like an oversight. Use panic!() instead if you actually intend to panic.
Code that is almost certainly wrong. Denied by default: the build fails until you fix it or allow it.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
for x in (0..100).step_by(0) {
//..
}
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::iterator_step_by_zero)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
iterator_step_by_zero = "allow"One run
cargo clippy -- -A clippy::iterator-step-by-zeroThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks for calling .step_by(0) on iterators which panics.
Why is this bad?
This very much looks like an oversight. Use panic!() instead if you
actually intend to panic.
Example
for x in (0..100).step_by(0) {
//..
}
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- invisible_charactersChecks for invisible Unicode characters in the code
- iter_next_loopChecks for loops on x.next()
- iter_skip_zerousage of `.skip(0)`
- let_underscore_lockChecks for let _ = sync_lock
- lint_groups_priorityChecks for lint groups with the same priority as lints in the Cargo.toml [lints] table. This lint will be removed once cargo#12918 is resolved
- match_str_case_mismatchChecks for match expressions modifying the case of a string with non-compliant arms
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::invisible_charactersChecks for invisible Unicode characters in the codeRead it next →Did this answer your question?