rust-clippy
rust-clippy copied to clipboard
Iterators: suggest `position()` instead of `enumerate() + find() + .0`
This is sort of the opposite of #456. I recently wrote let idx = v.iter().enumerate().find(|&(_, &ch)| ch == '|').unwrap().0, when I should have written let idx = v.iter().position(|&ch| ch == '|').unwrap(). I'd have to think a little on the exact rule that should be followed here, but it would be nice if clippy could catch this pattern.
This should be a simple addition to the iterator method chain lint
I'm taking a look at this - looks like an addition to methods.rs.
It seems that this issue has gone stale. I'd like to implement this if there is still interest. One question though: What about cases like v.iter().enumerate().find(|&(_, &ch)| ch == '|').map(|x| x.0) which is the same as v.iter().position(|&(_, &ch)| ch == '|')?
I'm filling to attempt to implement this and submit a PR if it is still relevant.
@rustbot claim