Lint useless or-pattern alternatives under unreachable_patterns - #161613
Draft
iMostfa wants to merge 1 commit into
Draft
Lint useless or-pattern alternatives under unreachable_patterns#161613iMostfa wants to merge 1 commit into
iMostfa wants to merge 1 commit into
Conversation
iMostfa
force-pushed
the
useless-or-pattern-alternatives
branch
from
August 23, 2026 17:48
60dab36 to
8dc23e4
Compare
Collaborator
|
The job Click to see the possible cause of the failure (guessed by this bot) |
Contributor
|
☔ The latest upstream changes (presumably #161706) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rustc warns when an or-pattern alternative is unreachable (
_ | 0), but not when it is reachable yet useless (0 | _): removing it wouldn't change the result of the match.Teach the usefulness algorithm to detect such alternatives and lint them under
unreachable_patterns, with a dedicated "useless pattern" message since they are not unreachable. Being semantic rather than syntactic, this also catches what clippy can't: coverage by a union of siblings (0..=1 | 1..=2 | 2..=3) and duplicates in guarded arms (0 | 0 if g). Alternatives that bind variables are not linted, since which alternative matches determines the bound values ((0, x) | (x, _)).The lint found two real cases in rustc's own sources, fixed here. Existing consumers of
rustc_pattern_analysis(rust-analyzer) keep compiling unchanged.Fixes #160772