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
fix: unnecessary_filter_map return of Some arg #12766
base: master
Are you sure you want to change the base?
fix: unnecessary_filter_map return of Some arg #12766
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @llogiq (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
&& arg_id.ty_def_id() == args[0].hir_id().ty_def_id() | ||
{ | ||
if let hir::ExprKind::Path(_) = args[0].kind { | ||
span_lint(cx, UNNECESSARY_FILTER_MAP, arg.span, &format!("{name} is unnecessary")) |
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.
it just occurs to me that... could this be span_lint_with_sugg
instead 🤔 , suggesting removing the filter_map
?
same thing applies here, while suggest replacing the method call, with MaybeIncorrect
applicability for both ofc...
@@ -21,6 +22,8 @@ fn main() { | |||
//~^ ERROR: this `.filter_map` can be written more simply using `.map` | |||
|
|||
let _ = (0..4).filter_map(i32::checked_abs); | |||
|
|||
let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x)); |
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 linked issue also mentions passing a path to Some
, so maybe we should add this as a test too
let _ = (0..4).filter_map(Some);
fixes #12556
changelog: [
unnecessary_filter_map
]: filter map return arg as Some