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
pubstructFoo{x:[f32;3]}pubfnfoo(x:&mutFoo,p:&mut[f32]){for i in0..3{
x.x[i] += p[i];}}
produces
warning: the loop variable `i` is used to index `p`
--> src/main.rs:6:14
|
6 | for i in 0..3 {
| ^^^^
|
= note: #[warn(needless_range_loop)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#needless_range_loop
help: consider using an iterator
|
6 | for (i, <item>) in p.iter().enumerate().take(3) {
| ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
which suggests that only p is indexed, or at least disregards that x.x is also indexed. In this case, zip would probably be a much better recommendation than using any kind of index.
Using the index to index all of the variables but one feels a bit weird:
Playground:
produces
which suggests that only
p
is indexed, or at least disregards thatx.x
is also indexed. In this case,zip
would probably be a much better recommendation than using any kind of index.Using the index to index all of the variables but one feels a bit weird:
Also, in this case, a
zip
would not require thetake(3)
because the length would be fixed as part of thezip
.The text was updated successfully, but these errors were encountered: