-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
.
Lint Name
range_zip_with_len
Reproducer
I tried this code:
pub fn iter_too(v: &[u32]){
for (_, i) in v.iter().zip(0..v.len()) {
assert!(i <= v.len());
}
}
pub fn main() {}I saw this happen:
warning: using `.zip()` with a range and `.len()`
--> src/main.rs:2:19
|
2 | for (_, i) in v.iter().zip(0..v.len()) {
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `v.iter().enumerate()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#range_zip_with_len
= note: `#[warn(clippy::range_zip_with_len)]` on by default
The suggested code
pub fn iter_too(v: &[u32]){
for (_, i) in v.iter().enumerate() {
assert!(i <= v.len());
}
}
pub fn main() {}does not compile
error[E0308]: mismatched types
--> src/main.rs:3:22
|
3 | assert!(i <= v.len());
| ^^^^^^^ expected `&u32`, found `usize`
For more information about this error, try `rustc --explain E0308`.
Version
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have