rust-clippy
rust-clippy copied to clipboard
Detect `.map_or(false, f)` in `manual_is_variant_and` lint
.map_or(false, f) on a Option or a Result was not detected by manual_is_variant_and.
This change is small (first commit), but induces a lot of (rightful) fixes (second commit) in Clippy sources.
changelog: [manual_is_variant_and]: add detection of .map_or(false, f) pattern
r? @Manishearth
rustbot has assigned @Manishearth. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.
Use r? to explicitly pick a reviewer
FWIW, this is also being implemented in #11796, though as a new lint and not part of manual_is_variant_and since the PR predates it
FWIW, this is also being implemented in #11796, though as a new lint and not part of
manual_is_variant_andsince the PR predates it
Oh. So what do we do? Although I think this check rather belongs to manual_is_variant_of and should be machine applicable, I don't mind dropping it if @Jacherr prefer to finalize their PR instead.
Moreover, @Jacherr PR could be retargeted to catch instances of .is_some_and(|x| x == V) (or .is_ok_and(|x| x == V)) and propose rewriting them as == Some(V) or == Ok(V). It could be applied in some cases after the current PR, and will catch more cases of code already using .is_some_and() and .is_ok_and().
The existing PR is pretty far through the review process and as far as I know just needs a few more changes before being ready for merging. I just need time to get round to it!
As is, I’m not sure there’s much benefit complicating the situation even further with that PR because it’s been open for almost a year now (oops..) As for these improvements, they can probably be retroactively applied after the fact (either by myself or you).
Fine with me, I'll keep this PR in my own version for the time being so that I can benefit from the lint (I detected some usages of .map_or(false, …) in some of my code and got it fixed using it) until your PR is merged, and I'll close it when your is in.
On vacation for a week. Feel free to retarget review with r? clippy