Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

needless_collect has rediculous spans #6908

Closed
matthiaskrgr opened this issue Mar 14, 2021 · 0 comments · Fixed by #7020
Closed

needless_collect has rediculous spans #6908

matthiaskrgr opened this issue Mar 14, 2021 · 0 comments · Fixed by #7020
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@matthiaskrgr
Copy link
Member

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)

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions labels Mar 14, 2021
@camsteffen camsteffen added the good-first-issue These issues are a good way to get started with Clippy label Mar 29, 2021
@bors bors closed this as completed in 86fb0e8 Apr 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants