Skip to content

Handle non-adjacent boolean arms in match_like_matches_macro - #17624

Open
fzlzjerry wants to merge 2 commits into
rust-lang:masterfrom
fzlzjerry:fix/17616-match-like-tft
Open

Handle non-adjacent boolean arms in match_like_matches_macro#17624
fzlzjerry wants to merge 2 commits into
rust-lang:masterfrom
fzlzjerry:fix/17616-match-like-tft

Conversation

@fzlzjerry

@fzlzjerry fzlzjerry commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

changelog: [match_like_matches_macro]: lint boolean matches with non-adjacent equal-result arms

Fixes #17616

Summary

  • group guard-free boolean-literal arms by their result instead of requiring one identical-result prefix
  • keep wildcard patterns out of the suggestion by selecting the opposite result group
  • preserve match-arm precedence by bailing when a selected pattern overlaps an earlier arm with the opposite result
  • share pattern normalization and overlap analysis through the matches::pat_overlap utility
  • cover T-F-T matches, mixed wildcard fallbacks, overlapping patterns, and uniform-result matches
  • update Clippy's dogfood matches exposed by the broader lint

Validation

  • TESTNAME=match_like_matches_macro cargo uitest
  • TESTNAME=match_same_arms cargo uitest
  • cargo test --test dogfood
  • cargo dev fmt --check
  • cargo test

Related work

#17505 independently fixes binding redaction in combined or-pattern suggestions and touches the same suggestion builder. This branch leaves that work there and can be rebased after it lands.

Copilot AI lite review requested due to automatic review settings August 24, 2026 13:55
@rustbot

rustbot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request. A reviewer will take a look after it receives 2 community reviews.

In the meantime, we would highly appreciate if you could try to review any of PRs waiting on community reviews.

@rustbot rustbot added S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Aug 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown

Lintcheck changes for dc93a16

Lint Added Removed Changed
clippy::match_like_matches_macro 7 0 0
clippy::match_same_arms 0 9 1

This comment will be updated if you push new changes

@CommanderStorm CommanderStorm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this mostly looks good, but there are a lot of changes and honestly there might be gaps.

View changes since this review

Comment thread clippy_lints/src/matches/match_like_matches.rs
Comment thread clippy_lints/src/matches/match_like_matches.rs
Comment thread clippy_lints/src/matches/match_like_matches.rs Outdated
Comment thread clippy_lints/src/matches/match_same_arms.rs Outdated

@CommanderStorm CommanderStorm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Community review: LGTM.
I would ask you to squash the commits down to the appropriate amount, so likely 2 (the pat_overlap and the actual lint+test change)

View changes since this review

@fzlzjerry
fzlzjerry force-pushed the fix/17616-match-like-tft branch from adb475e to dc93a16 Compare August 26, 2026 06:40
@fzlzjerry

Copy link
Copy Markdown
Contributor Author

Rewrote the branch history into the two requested logical commits:

  • 034e59ca0 extracts the normalized-pattern overlap analysis into matches::pat_overlap
  • dc93a16fa contains the lint behavior, regression coverage, and dogfood updates

The resulting tree is identical to the approved adb475e9b tree. I also verified the extraction commit independently with the 8 match_same_arms UI cases, then reran formatting and the 3 match_like_matches_macro UI cases on the final head; the prior dogfood and full cargo test run applies to the byte-identical final tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. 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.

match_like_matches_macro does not lint on T-F-T-style matches

4 participants