rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Add `manual_filter` lint for `Option`

Open kraktus opened this issue 3 years ago • 3 comments

Share much of its implementation with manual_map and should greatly benefit from its previous feedback. I'm sure it's possible to even more refactor both and would gladly take input on that as well as any clippy idiomatic usage, since this is my first lint addition.

I've added the lint to the complexity section for now, I don't know if every new lint needs to go in nursery first.

The matching could be expanded to more than Some(<value>) to lint on arbitrary struct matching inside the Some but I've left it like it was for manual_map for now. needless_match::pat_same_as_expr provides a more generic match example.

close https://github.com/rust-lang/rust-clippy/issues/8822

changelog: Add lint [manual_filter] for Option

kraktus avatar Sep 09 '22 20:09 kraktus

r? @dswij

(rust-highfive has picked a reviewer for you, use r? to override)

rust-highfive avatar Sep 09 '22 20:09 rust-highfive

I don't know if every new lint needs to go in nursery first.

There's no requirement to go to nursery first. I'll try to run this on the most popular crates to see if there's lots of FPs. If not, then I think complexity is fine.

dswij avatar Sep 16 '22 12:09 dswij

I ran this on 900 most popular crates. Here's the result.

At first glance, it seems to work as expected. I'll try taking a look further when time hopefully allows

dswij avatar Sep 16 '22 15:09 dswij

:umbrella: The latest upstream changes (presumably #9525) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Sep 23 '22 21:09 bors

:umbrella: The latest upstream changes (presumably #9484) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Oct 01 '22 21:10 bors

:umbrella: The latest upstream changes (presumably #7962) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Oct 02 '22 19:10 bors

Sounds good! Build failures are on crate where the lint does not trigger indeed

kraktus avatar Oct 05 '22 06:10 kraktus

Thanks for this! @bors r+

dswij avatar Oct 08 '22 15:10 dswij

:pushpin: Commit 830fdf2b56d2a2f0f8e8135e05ec30b08e54ad3a has been approved by dswij

It is now in the queue for this repository.

bors avatar Oct 08 '22 15:10 bors

:hourglass: Testing commit 830fdf2b56d2a2f0f8e8135e05ec30b08e54ad3a with merge 292e313259f422c8f4c31ecaedcc14058e8f4f8b...

bors avatar Oct 08 '22 15:10 bors

:sunny: Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test Approved by: dswij Pushing 292e313259f422c8f4c31ecaedcc14058e8f4f8b to master...

bors avatar Oct 08 '22 16:10 bors