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 needless_match FP on if-lets #13646

Merged
merged 1 commit into from
Dec 2, 2024
Merged

Conversation

blyxyas
Copy link
Member

@blyxyas blyxyas commented Nov 2, 2024

Closes #13574

Make sure that needless_match doesn't simplify:

if let Some(_) = a() {
// ..
} else let Some(_) = b() {
// ..
}

to:

a()

changelog: [needless_match]: Fix false-positive on if lets

@rustbot
Copy link
Collaborator

rustbot commented Nov 2, 2024

r? @Centri3

rustbot has assigned @Centri3.
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 Nov 2, 2024
Copy link
Member

@Centri3 Centri3 left a comment

Choose a reason for hiding this comment

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

This'll need to check method calls too, at least. It doesn't really seem like it checks the init expr at all before this, does it? So for example, mixing functions & constants has the same issue.

@blyxyas
Copy link
Member Author

blyxyas commented Nov 13, 2024

I'm not sure if we should just get two snippets at that point, I'll try doing manual pattern matching, but it might be the simplest solution

@Centri3
Copy link
Member

Centri3 commented Nov 14, 2024

There is eq_expr_value for that purpose, whose body is just:

SpanlessEq::new(cx).deny_side_effects().eq_expr(left, right)

Note that, in this case, any functions will be denied due to potentially having side effects (even if there are none). So, calling it manually might be better. Should work fine I think, even if it's a bit strict?

This is already used here and should be an ok, simple solution (I think).

@Centri3 Centri3 added this pull request to the merge queue Dec 2, 2024
Merged via the queue into rust-lang:master with commit 278e316 Dec 2, 2024
9 checks passed
@blyxyas blyxyas deleted the fix-13574 branch December 2, 2024 14:35
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.

Overzealous clippy::needless_match with multiple chained if let blocks
3 participants