Closed
Description
fn main() {
let v = vec![1,2,3,4].into_iter().collect::<Vec<_>>();
//
//
//
// lol can't see me!
for i in &[3,4] {
if v.contains(&i) {
println!("got {}", i);
}
}
}
clippys "suggestion":
warning: avoid using `collect()` when not needed
--> src/main.rs:2:1
|
2 | / let v = vec![1,2,3,4].into_iter().collect::<Vec<_>>();
3 | |
4 | | //
5 | | //
... |
8 | | for i in &[3,4] {
9 | | if v.contains(&i) {
| |_______^
|
= note: `#[warn(clippy::needless_collect)]` on by default
help: check if the original Iterator contains an element instead of collecting then checking
|
2 |
3 |
4 | //
5 | //
6 | //
7 | // lol can't see me!
...
warning: 1 warning emitted
Looks like the suggestion span is looking at the position of the collect()
and not the position of the .contains()
...?
clippy 0.1.52 (acca818 2021-03-13)