rust/tests/ui/range.fixed
Samuel Tardieu ea2ea62fd1
Note that using enumerate() will swap the arguments
The autofix now:

- includes the swapping of index and element in the closure in which the
  content will be consumed;
- notes, with applicability `MaybeIncorrect` (because it will be), that
  the element and the index will be swapped.
2025-06-04 15:51:41 +02:00

31 lines
666 B
Rust

#![allow(clippy::useless_vec)]
#[warn(clippy::range_zip_with_len)]
fn main() {
let v1: Vec<u64> = vec![1, 2, 3];
let v2: Vec<u64> = vec![4, 5];
let _x = v1.iter().enumerate();
//~^ range_zip_with_len
//~v range_zip_with_len
for (i, e) in v1.iter().enumerate() {
let _: &u64 = e;
let _: usize = i;
}
//~v range_zip_with_len
v1.iter().enumerate().for_each(|(i, e)| {
let _: &u64 = e;
let _: usize = i;
});
let _y = v1.iter().zip(0..v2.len()); // No error
}
#[allow(unused)]
fn no_panic_with_fake_range_types() {
struct Range {
foo: i32,
}
let _ = Range { foo: 0 };
}