Skip to content
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

Conversation

omer-shtivi
Copy link

fixes #12556
changelog: [unnecessary_filter_map]: filter map return arg as Some

@rustbot
Copy link
Collaborator

rustbot commented May 6, 2024

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 6, 2024
&& 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"))
Copy link
Member

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));
Copy link
Contributor

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);

Copy link
Contributor

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 😎

@bors
Copy link
Contributor

bors commented Jun 7, 2024

☔ The latest upstream changes (presumably #12897) made this pull request unmergeable. Please resolve the merge conflicts.

Comment on lines +45 to +48
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

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?

@xFrednet
Copy link
Member

xFrednet commented Jul 4, 2024

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

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 4, 2024
@xFrednet
Copy link
Member

xFrednet commented Aug 3, 2024

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

@xFrednet xFrednet closed this Aug 3, 2024
@rustbot rustbot added S-inactive-closed Status: Closed due to inactivity and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Aug 3, 2024
bors added a commit that referenced this pull request Oct 27, 2024
…ome, r=llogiq

fix: remove unnecessary filter_map usages

fixes #12556

(Fixed version of #12766)

changelog: [unnecessary_filter_map]: filter map improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive-closed Status: Closed due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggest removing filter_map for Iterator::filter_map(|x| Some(x))
7 participants