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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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