-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
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);
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 more tests the merrier 😎
☔ The latest upstream changes (presumably #12897) made this pull request unmergeable. Please resolve the merge conflicts. |
if is_res_lang_ctor(cx, path_res(cx, expr), OptionSome) | ||
&& arg_id.ty_def_id() == args[0].hir_id().ty_def_id() | ||
{ | ||
if let hir::ExprKind::Path(_) = args[0].kind { |
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.
if is_res_lang_ctor(cx, path_res(cx, expr), OptionSome) | |
&& arg_id.ty_def_id() == args[0].hir_id().ty_def_id() | |
{ | |
if let hir::ExprKind::Path(_) = args[0].kind { | |
if is_res_lang_ctor(cx, path_res(cx, expr), OptionSome) | |
&& arg_id.ty_def_id() == args[0].hir_id().ty_def_id() | |
&& let hir::ExprKind::Path(_) = args[0].kind { |
let chains for the win!
@@ -1,3 +1,4 @@ | |||
//@no-rustfix |
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.
Is the whole test rustfix-incompatible? If not, could we split our a -fix
test file?
Hey @omer-shtivi , this is a ping from triage, since there hasn't been any activity in some time. Are you still planning to continue this implementation? If you have any questions, you're always welcome to ask them in this PR or on Zulip. @rustbot author |
Hey this is triage, I'm closing this due to inactivity. If you want to continue this implementation, you're welcome to create a new PR. Thank you for the time, you already put into this! Interested parties are welcome to pick this implementation up as well :) @rustbot label +S-inactive-closed -S-waiting-on-author -S-waiting-on-review |
fixes #12556
changelog: [
unnecessary_filter_map
]: filter map return arg as Some