mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
e097fca4df
Move `iterator_step_by_zero` into `methods` since it applies to all iterators and not just ranges. Simplify the code while doing so.
28 lines
593 B
Rust
28 lines
593 B
Rust
#[warn(clippy::iterator_step_by_zero)]
|
|
fn main() {
|
|
let _ = vec!["A", "B", "B"].iter().step_by(0);
|
|
let _ = "XXX".chars().step_by(0);
|
|
let _ = (0..1).step_by(0);
|
|
|
|
// No error, not an iterator.
|
|
let y = NotIterator;
|
|
y.step_by(0);
|
|
|
|
// No warning for non-zero step
|
|
let _ = (0..1).step_by(1);
|
|
|
|
let _ = (1..).step_by(0);
|
|
let _ = (1..=2).step_by(0);
|
|
|
|
let x = 0..1;
|
|
let _ = x.step_by(0);
|
|
|
|
// check const eval
|
|
let v1 = vec![1, 2, 3];
|
|
let _ = v1.iter().step_by(2 / 3);
|
|
}
|
|
|
|
struct NotIterator;
|
|
impl NotIterator {
|
|
fn step_by(&self, _: u32) {}
|
|
}
|