Skip to content

Fixed short span (duplicate match arms) in match_same_arms lint#16831

Open
shashu8660 wants to merge 3 commits intorust-lang:masterfrom
shashu8660:fix-span-in-match-same-arms
Open

Fixed short span (duplicate match arms) in match_same_arms lint#16831
shashu8660 wants to merge 3 commits intorust-lang:masterfrom
shashu8660:fix-span-in-match-same-arms

Conversation

@shashu8660
Copy link
Copy Markdown

changelog: [match_same_arms]: highlight only duplicate match arms instead of the original arm

Previously, the lint highlighted the first (original) match arm when identical arms were detected. I added UI tests to verify this behavior.

However, the lint should point to the duplicate arms rather than the original one. This change updates the span to include only duplicate arms by skipping the first element in the group, ensuring that the diagnostic points to the actual redundant code.

All tests pass, and the .stderr / .fixed outputs are updated accordingly.

This change addresses part of the Outreachy task described in:
rustfoundation/interop-initiative#53

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 9, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 9, 2026

r? @Jarcho

rustbot has assigned @Jarcho.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

Lintcheck changes for 95a6ba0

Lint Added Removed Changed
clippy::match_same_arms 271 271 15

This comment will be updated if you push new changes

@shashu8660

This comment was marked as low quality.

@teor2345
Copy link
Copy Markdown
Contributor

Hi @shashu8660 I think maybe you've changed a different part of the code?

The issue is that this line ignores the vertical tab character:
https://github.com/rust-lang/rust/blob/e0e95a71872dfe9e15d22bddea9ac45c85ddda1a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs#L180

But it should include vertical tab (and maybe other Unicode whitespace in the Rust language):
https://doc.rust-lang.org/reference/whitespace.html

To test for this issue:

  • create a match statement with identical arms
  • add vertical tab whitespace in the match arms, I think it needs to be near the comma
  • notice how the span isn't extended to include the vertical tab

@shashu8660

This comment was marked as low quality.

@teor2345
Copy link
Copy Markdown
Contributor

  • Is my current PR still useful in any way, or should I close it?

I don't know, because I can't see how the code behaves before and after this change.

Please edit the PR description to show:

  • some example code that triggers the lint
  • an example of the span before the code change
  • an example of the same span after the code change

When we can see how the span has changed, reviewers will be able to tell you if it is useful.

@shashu8660

This comment was marked as low quality.

@teor2345
Copy link
Copy Markdown
Contributor

Sure, I can do that @shashu8660. But I still want to understand how you got from rustfoundation/interop-initiative#53 to this PR.

It doesn't seem related to the original task. And the PR description says the tests pass, but CI shows they don't. So that's weird.

Did you copy the PR description from somewhere else, or use Copilot or something similar to write it for you?

Before anyone spends more time reviewing your PRs, we need to understand how you are creating them.

@shashu8660

This comment was marked as low quality.

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.

4 participants