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

Removing @rust-nofix from match_same_arms requires lint fixes #13835

Open
scottgerring opened this issue Dec 16, 2024 · 1 comment
Open

Removing @rust-nofix from match_same_arms requires lint fixes #13835

scottgerring opened this issue Dec 16, 2024 · 1 comment
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@scottgerring
Copy link
Contributor

scottgerring commented Dec 16, 2024

Summary

In #13803 together with @blyxyas we discovered that match_same_arms does not deal with cases where more than 2 arms have the same body. E.g. this test:

let _ = match 42 {
1 => 2,
2 => 2, //~ ERROR: this match arm has an identical body to another arm
//~^ ERROR: this match arm has an identical body to another arm
3 => 2, //~ ERROR: this match arm has an identical body to another arm
4 => 3,
_ => 0,
};

Will generate two overlapping suggestions - one to combine 1 and 2, one to combine 2 and 3. This means the lint cannot be automatically applied, and @rust-nofix remains.

It looks like the issue is that the arms are matched up pairwise, rather than collecting all that have the same body and suggesting an aggregate fix:

for (&(i, arm1), &(j, arm2)) in search_same(&indexed_arms, hash, eq) {
if matches!(arm2.pat.kind, PatKind::Wild) {

We should change this to aggregate all equivalent bodies and provide a single suggestion to combine them.

Reproducer

Remove @rust-nofix from match_same_arms and check out the overlapping application failure for the test code linked above.

Version


Additional Labels

No response

@scottgerring scottgerring added the C-bug Category: Clippy is not doing the correct thing label Dec 16, 2024
@scottgerring
Copy link
Contributor Author

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

1 participant