Fixes a collapsible_match false positive where the suggested fix turned an exhaustive match into a non-exhaustive one.#16911
Open
Souradip121 wants to merge 3 commits intorust-lang:masterfrom
Conversation
Collaborator
|
r? @dswij rustbot has assigned @dswij. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Lintcheck changes for a91feec
This comment will be updated if you push new changes |
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.
When the inner
if cond { A } else { B }was collapsed into a guarded outer arm and theouter "wild-like" sibling arm was
None(a constructor pattern, not a true catch-all),the suggestion dropped the inner
elsebody and produced amatchthat no longercovered
Some(_)when the guard failed.Closes #16910
What changed
arm_is_wild_likeacceptsWild,Binding, andOptionNone. The first two aretrue catch-alls;
OptionNoneis wild-LIKE but only matchesNone, so it cannot catcha
Some(_)value falling through from a guardedSome(_)arm above.Path B (inner plain
if) was already gated ononly_wildcards_after(added in #16875to handle a similar case where a
_ if condarm intercepts the fall-through). That gatehas been tightened: every arm after the one being collapsed must be unconditional with
a
_or binding pattern, and at least one such arm must exist. This catches both theprior
_ if condcase and the newNonecase.Reproducer (from the issue, simplified)
Before the fix the lint suggested:
After the fix the lint stays silent on this shape.
Conditions for the if-guard collapse to fire
match_or bindingpattern, and there is at least one such arm
guard, etc.)
changelog: [
collapsible_match]: no longer suggests a fix that drops anelsebranch when the fall-through arm is wild-LIKE (e.g.None) but not a true catch-all