-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Suggest flatten
over filter(Option::is_some)
#11843
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
Comments
@rustbot claim |
This comment was marked as resolved.
This comment was marked as resolved.
🤔 This almost exists as |
Should I extend and/or possibly rename? |
IMO it could make sense to have this as a new lint, given that this changes types of iterator chains and may not be as applicable as |
@y21 maybe I am missing something but there doesn't seem to be a |
How do you think this should be tackled in light of the missing mirror? Maybe I can add both the mirror and this? |
IMO it does make sense to add a mirror for the |
New lints `iter_filter_is_some` and `iter_filter_is_ok` Adds a pair of lints that check for cases of an iterator over `Result` and `Option` followed by `filter` without being followed by `map` as that is covered already by a different, specialized lint. Fixes #11843 PS, I also made some minor documentations fixes in a case where a double tick (`) was included. --- * changelog: New Lint: [`iter_filter_is_some`] [#12004](rust-lang/rust#12004) * changelog: New Lint: [`iter_filter_is_ok`] [#12004](rust-lang/rust#12004)
What it does
Checks for usage of
filter(Option::is_some)
orfilter(Result::is_ok)
on anIterator
.This is more succinctly written with just
flatten()
.Careful: The suggestion must be
MaybeIncorrect
, as this changes the type of the iterator fromItem = Option<T>
toItem = T
.good-first-issue
instructions: This lint should be quite easy to add as anotherclippy_lints/src/methods/
lint. All of the parts required to check for this should already be there and can be reused.Advantage
Drawbacks
Changes the type of the iterator chain. This will lead to more refactorings required down the chain. But I think in most cases this will benefit the code complexity overall.
Example
Could be written as:
Playground
The text was updated successfully, but these errors were encountered: