Skip to content

needless_collect has rediculous spans #6908

Closed
@matthiaskrgr

Description

@matthiaskrgr
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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingL-suggestionLint: Improving, adding or fixing lint suggestionsgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions