You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
This example code produces the clippy error below.
The warning is incorrect.
i
is used in the closure within themap
call. The suggestion won't work because of that.The text was updated successfully, but these errors were encountered: