Repository navigation
Conversation
Collaborator
|
r? @jackh726 rustbot has assigned @jackh726. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment was marked as resolved.
This comment was marked as resolved.
fmease
force-pushed
the
allow-paren-guarded-pat-in-match-arm
branch
from
October 17, 2026 14:58
bcae0e4 to
784c75e
Compare
This branch has not been deployed
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.
This PR renders
match $expr { ($pat if $expr) => $expr }syntactically legal under unstable featureguard_patterns. RFC 3637 does not forbid it, meaning the current implementation doesn't follow the specification.The only reason why the current implementation rejects code like this is the fact that prior to the introduction of guard patterns in PR #133424 we already had parse error recovery & a custom diagnostic in place for, well, "accidentally parenthesized match arm patterns with guard". I guess the authors of #133424 did not want to regress the diagnostics here & so opted to leave that case alone (leaving a FIXME).
Furthermore, the error recovery code is hairy & verbose, so I'd like to see it simplified or gone. Fortunately, we can have the cake & eat it, too: We can allow match arm pat
($pat if $expr)ifguard_patternsis enabled and continue to provide that custom-tailored diagnostic if it's not enabled (unless the code is cfg'ed out / dropped during expansion which is absolutely acceptable).Note that we can't just query "is feature
guard_patternsenabled" from inside the parser to know when not to emit the custom diagnostic because the answer depends on macro expansion. So instead, we entirely remove this logic from the parser and do it incompiler/rustc_ast_passes/src/feature_gate.rswhere we have access to the list of all enabled features (& toSessionfor queryingis_nightly_build).Part of #129967.
(No LLM was or will be used by me during the entire creation process of this PR)