mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-02 17:40:13 +00:00
Put tests for step_by(0)
back.
This commit is contained in:
parent
85384afca3
commit
a80db63515
2 changed files with 46 additions and 4 deletions
|
@ -10,9 +10,16 @@ impl NotARange {
|
||||||
|
|
||||||
#[warn(iterator_step_by_zero, range_zip_with_len)]
|
#[warn(iterator_step_by_zero, range_zip_with_len)]
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let _ = (0..1).step_by(0);
|
||||||
// No warning for non-zero step
|
// No warning for non-zero step
|
||||||
let _ = (0..1).step_by(1);
|
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);
|
||||||
|
|
||||||
// No error, not a range.
|
// No error, not a range.
|
||||||
let y = NotARange;
|
let y = NotARange;
|
||||||
y.step_by(0);
|
y.step_by(0);
|
||||||
|
@ -21,4 +28,7 @@ fn main() {
|
||||||
let v2 = vec![4,5];
|
let v2 = vec![4,5];
|
||||||
let _x = v1.iter().zip(0..v1.len());
|
let _x = v1.iter().zip(0..v1.len());
|
||||||
let _y = v1.iter().zip(0..v2.len()); // No error
|
let _y = v1.iter().zip(0..v2.len()); // No error
|
||||||
|
|
||||||
|
// check const eval
|
||||||
|
let _ = v1.iter().step_by(2/3);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,44 @@
|
||||||
error: It is more idiomatic to use v1.iter().enumerate()
|
error: Iterator::step_by(0) will panic at runtime
|
||||||
--> range.rs:22:14
|
--> range.rs:13:13
|
||||||
|
|
|
|
||||||
22 | let _x = v1.iter().zip(0..v1.len());
|
13 | let _ = (0..1).step_by(0);
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: `-D iterator-step-by-zero` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: Iterator::step_by(0) will panic at runtime
|
||||||
|
--> range.rs:17:13
|
||||||
|
|
|
||||||
|
17 | let _ = (1..).step_by(0);
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: Iterator::step_by(0) will panic at runtime
|
||||||
|
--> range.rs:18:13
|
||||||
|
|
|
||||||
|
18 | let _ = (1...2).step_by(0);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: Iterator::step_by(0) will panic at runtime
|
||||||
|
--> range.rs:21:13
|
||||||
|
|
|
||||||
|
21 | let _ = x.step_by(0);
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: It is more idiomatic to use v1.iter().enumerate()
|
||||||
|
--> range.rs:29:14
|
||||||
|
|
|
||||||
|
29 | let _x = v1.iter().zip(0..v1.len());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `-D range-zip-with-len` implied by `-D warnings`
|
= note: `-D range-zip-with-len` implied by `-D warnings`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: Iterator::step_by(0) will panic at runtime
|
||||||
|
--> range.rs:33:13
|
||||||
|
|
|
||||||
|
33 | let _ = v1.iter().step_by(2/3);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
|
||||||
To learn more, run the command again with --verbose.
|
To learn more, run the command again with --verbose.
|
||||||
|
|
Loading…
Reference in a new issue