Skip to content

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

Closed
@scottgerring

Description

@scottgerring

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions