-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New Lint: result_filter_map
/ Mirror of option_filter_map
#11869
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
Conversation
r? @Alexendoo (rustbot has picked a reviewer for you, use r? to override) |
As I suggested this, I'd like to get a second opinion from a different reviewer on this :) thanks for the ping though! |
@rustbot ready |
result_filter_map
/ Mirror of ok_filter_map
result_filter_map
/ Mirror of option_filter_map
Yes, that's what I had in mind. |
clippy_lints/src/methods/mod.rs
Outdated
@@ -3752,6 +3752,28 @@ declare_clippy_lint! { | |||
"using `Option.map_or(Err(_), Ok)`, which is more succinctly expressed as `Option.ok_or(_)`" | |||
} | |||
|
|||
declare_clippy_lint! { | |||
/// ### What it does | |||
/// Checks for indirect collection of populated `Result` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this wording is copied from option_filter_map
but it would be good to change it in both places since it sounds like it's talking about .collect()
, maybe go very literal along the lines of
Checks for iterators of
Result
s using.filter(Result::is_ok).map(Result::unwrap)
that can be replaced with.flatten()
clippy_lints/src/methods/mod.rs
Outdated
/// `Result` is like a collection of 0-1 things, so `flatten` | ||
/// automatically does this without suspicious-looking `unwrap` calls. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "0-1 things" doesn't apply that well to Result
, you could instead mention directly that this works because Result<T, E>
implements IntoIterator<Item = T>
Sorry for the delay, life's gotten pretty busy lately. I have made the appropriate changes. |
@Alexendoo is everything okay with this? |
Just that and I think it's good to go |
Added the `Result` mirror of `option_filter_map` to catch ``` .into_iter().filter(Result::is_ok).map(Result::unwrap) ``` changelog: New Lint: [`result_filter_map`] Co-authored-by: Alex Macleod <[email protected]>
Thanks! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Added the
Result
mirror ofoption_filter_map
.changelog: New Lint: [
result_filter_map
]I had to move around some code because the function def was too long 🙃.
I have also added some pattern checks on
option_filter_map