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: spans are off by one #7200

Closed
matthiaskrgr opened this issue May 9, 2021 · 3 comments · Fixed by #7289
Closed

needless_collect: spans are off by one #7200

matthiaskrgr opened this issue May 9, 2021 · 3 comments · Fixed by #7289
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@matthiaskrgr
Copy link
Member

warning: avoid using `collect()` when not needed
   --> src/clean_unref.rs:214:86
    |
214 |     let required_crates: Vec<_> = required_crates.into_iter().map(SourceKind::inner).collect();
    |                                   ---------------------------                        ^^^^^^^
    |                                   |
    |                                   the iterator could be used here instead
    |
note: the lint level is defined here
   --> src/main.rs:29:5
    |
29  |     clippy::perf,
    |     ^^^^^^^^^^^^
    = note: `#[warn(clippy::needless_collect)]` implied by `#[warn(clippy::perf)]`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect
help: use the original Iterator instead of collecting it and then producing a new one
    |
214 |     required_crates.into_iter().map(SourceKind::inner).map(SourceKind::inner).collect();
    |    --                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Looks like the spans are a bit off in the lower message?
I'm not sure if this is a clippy lint bug or a rustc diasgnostics bug.

@matthiaskrgr matthiaskrgr added the C-bug Category: Clippy is not doing the correct thing label May 9, 2021
@camsteffen
Copy link
Contributor

Do you have a reproducible example?

@matthiaskrgr
Copy link
Member Author

Ok I just saw, what is seven more strange is that the lint suggestion duplicates the .map() call in the suggestion. o.O

.map(SourceKind::inner) in the original code, required_crates.into_iter().map(SourceKind::inner).map(SourceKind::inner).collect(); in the suggested code..??!

@matthiaskrgr
Copy link
Member Author

Here's stand alone repro of the strange spans:

use std::path::PathBuf;

fn main() {
    let required_crates = vec![];
    let required_crates: Vec<_> = required_crates.into_iter().collect();

    let _ = vec![1, 2, 3]
        .iter()
        .filter(|x| !required_crates.contains(&PathBuf::new()));
}
warning: avoid using `collect()` when not needed
 --> src/main.rs:5:63
  |
5 |     let required_crates: Vec<_> = required_crates.into_iter().collect();
  |                                   --------------------------- ^^^^^^^
  |                                   |
  |                                   the iterator could be used here instead
  |
  = note: `#[warn(clippy::needless_collect)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect
help: use the original Iterator instead of collecting it and then producing a new one
  |
5 |     required_crates.into_iter().collect();
  |    --                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^

there's really something odd with these spans :D

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants