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 option_if_let_else when Err variant is ignored #14429

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dgulotta
Copy link

@dgulotta dgulotta commented Mar 18, 2025

This fixes an issue where clippy suggests passing a function that takes no arguments as the first argument of Result::map_or_else. The function needs to take one argument. Example that triggers the issue: Playground link

Fixes #10335.

changelog: [option_if_let_else]: fix incorrect suggestion when the contents of an Err variant are ignored

@rustbot
Copy link
Collaborator

rustbot commented Mar 18, 2025

r? @Manishearth

rustbot has assigned @Manishearth.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 18, 2025
Copy link
Contributor

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

Thanks for catching this. Since the issue had been closed and not reopened, this apparently flew under the radard.

Can you add a "Fixes #10335" in the PR description and squash your 3 commits into one?

@@ -188,14 +188,32 @@ LL + true
LL + })
|

error: use Option::map_or_else instead of an if let/else
Copy link
Member

Choose a reason for hiding this comment

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

issue: this lint says Option, and has Option in its name, we should probably not be linting here?

Copy link
Member

Choose a reason for hiding this comment

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

I guess we already lint on Result here.

Tbh I'm not convinced of the value of this lint overall, we should probably have a team discussion about it, but separately to that we shoudl figure out if it should also handle Result in the same lint (and if so, it needs to be updated)

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.

option_if_let_else generates wrong suggestion for Results
4 participants