-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing

Description
This example code produces the clippy error below.
pub fn example(list: &[[f64; 3]]) {
let mut x: [f64; 3] = [10.; 3];
for i in 0..3 {
x[i] = list
.iter()
.map(|item| item[i])
.sum::<f64>();
}
}
warning: the loop variable `i` is only used to index `x`.
--> src/lib.rs:4:5
|
4 | / for i in 0..3 {
5 | | x[i] = list
6 | | .iter()
7 | | .map(|item| item[i])
8 | | .sum::<f64>();
9 | | }
| |_____^
|
= note: #[warn(needless_range_loop)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.176/index.html#needless_range_loop
help: consider using an iterator
|
4 | for <item> in x.iter_mut().take(3) {
|
The warning is incorrect. i
is used in the closure within the map
call. The suggestion won't work because of that.
carueda and peter-lyons-kehl
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing