2023-06-06 15:56:57 -05:00
|
|
|
#![allow(clippy::useless_vec)]
|
2019-12-18 10:59:43 -06:00
|
|
|
#[warn(clippy::iterator_step_by_zero)]
|
|
|
|
fn main() {
|
|
|
|
let _ = vec!["A", "B", "B"].iter().step_by(0);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `Iterator::step_by(0)` will panic at runtime
|
|
|
|
//~| NOTE: `-D clippy::iterator-step-by-zero` implied by `-D warnings`
|
2019-12-18 10:59:43 -06:00
|
|
|
let _ = "XXX".chars().step_by(0);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `Iterator::step_by(0)` will panic at runtime
|
2019-12-18 10:59:43 -06:00
|
|
|
let _ = (0..1).step_by(0);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `Iterator::step_by(0)` will panic at runtime
|
2019-12-18 10:59:43 -06:00
|
|
|
|
|
|
|
// 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);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `Iterator::step_by(0)` will panic at runtime
|
2019-12-18 10:59:43 -06:00
|
|
|
let _ = (1..=2).step_by(0);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `Iterator::step_by(0)` will panic at runtime
|
2019-12-18 10:59:43 -06:00
|
|
|
|
|
|
|
let x = 0..1;
|
|
|
|
let _ = x.step_by(0);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `Iterator::step_by(0)` will panic at runtime
|
2019-12-18 10:59:43 -06:00
|
|
|
|
|
|
|
// check const eval
|
|
|
|
let v1 = vec![1, 2, 3];
|
|
|
|
let _ = v1.iter().step_by(2 / 3);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: `Iterator::step_by(0)` will panic at runtime
|
2019-12-18 10:59:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
struct NotIterator;
|
|
|
|
impl NotIterator {
|
|
|
|
fn step_by(&self, _: u32) {}
|
|
|
|
}
|