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

false negative on clippy::filter_next when filter and next wraps map #6423

Open
meltinglava opened this issue Dec 5, 2020 · 2 comments
Open
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@meltinglava
Copy link

meltinglava commented Dec 5, 2020

False negative when filter and next is wrapped around a map.

There might be a few other methods like map that will have the same effect.

I tried this code:

    v.windows(3)
        .enumerate()
        .filter(|(_, a)| a == &[true, false, true])
        .map(|(v, _)| v + 1)
        .next()
        .unwrap()

I expected to see this happen: Clippy to suggest

    v.windows(3)
        .enumerate()
        .find(|(_, a)| a == &[true, false, true])
        .map(|(v, _)| v + 1)
        .unwrap()

Instead, this happened: Nothing

Meta

  • cargo clippy -V: e.g. clippy 0.0.212 (1c389ff 2020-11-24)rust
  • rustc -Vv:
    rustc 1.50.0-nightly (1c389ffef 2020-11-24)
    binary: rustc
    commit-hash: 1c389ffeff814726dec325f0f2b0c99107df2673
    commit-date: 2020-11-24
    host: x86_64-unknown-linux-gnu
    release: 1.50.0-nightly
    
@meltinglava meltinglava added the C-bug Category: Clippy is not doing the correct thing label Dec 5, 2020
@flip1995 flip1995 added the C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages label Dec 5, 2020
@flip1995
Copy link
Member

flip1995 commented Dec 5, 2020

We could even suggest using find_map here.

@meltinglava
Copy link
Author

meltinglava commented Dec 5, 2020

We could even suggest using find_map here.

#4193 will have the same prolem here. I think its always correct to suggest find, and when the conservativness of find_map is figured out it can be applied here.

@phansch phansch added the I-false-negative Issue: The lint should have been triggered on code, but wasn't label Dec 18, 2020
@camsteffen camsteffen added the E-medium Call for participation: Medium difficulty level problem and requires some initial experience. label Feb 8, 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 C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

4 participants