Repository navigation
Parse guard patterns - #133424
Merged
Merged
Parse guard patterns#133424
Conversation
Collaborator
|
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
1 of 8 tasks
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Max Niederman <max@maxniederman.com>
Nadrieril
force-pushed
the
guard-patterns-parsing
branch
from
November 24, 2024 18:42
6f2c8e0 to
962c014
Compare
Nadrieril
marked this pull request as ready for review
November 24, 2024 20:21
Collaborator
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
Member
Author
|
@rustbot ready |
ytmimi
reviewed
Nov 24, 2024
fee1-dead
requested changes
Nov 28, 2024
Member
Author
|
@rustbot ready |
fee1-dead
requested changes
Dec 8, 2024
Member
Author
Contributor
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Dec 8, 2024
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#133424 (Parse guard patterns) - rust-lang#133733 ( compiletest: show the difference between the normalized output and the actual output for lines which didn't match) - rust-lang#133993 (Fix: typo in E0751 error explanation) - rust-lang#134013 (Adds new intrinsic declaration) - rust-lang#134020 (Remove unnecessary `int_type_width_signed` function) - rust-lang#134024 (Advent of `tests/ui` (misc cleanups and improvements) [2/N]) - rust-lang#134038 (deps: Update psm) r? `@ghost` `@rustbot` modify labels: rollup
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Dec 8, 2024
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#133424 (Parse guard patterns) - rust-lang#133733 ( compiletest: show the difference between the normalized output and the actual output for lines which didn't match) - rust-lang#133993 (Fix: typo in E0751 error explanation) - rust-lang#134013 (Adds new intrinsic declaration) - rust-lang#134020 (Remove unnecessary `int_type_width_signed` function) - rust-lang#134024 (Advent of `tests/ui` (misc cleanups and improvements) [2/N]) - rust-lang#134038 (deps: Update psm) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Dec 9, 2024
Rollup merge of rust-lang#133424 - Nadrieril:guard-patterns-parsing, r=fee1-dead Parse guard patterns This implements the parsing of [RFC3637 Guard Patterns](https://rust-lang.github.io/rfcs/3637-guard-patterns.html) (see also [tracking issue](rust-lang#129967)). This PR is extracted from rust-lang#129996 with minor modifications. cc `@max-niederman`
flip1995
pushed a commit
to flip1995/rust
that referenced
this pull request
Dec 15, 2024
…r=fee1-dead Parse guard patterns This implements the parsing of [RFC3637 Guard Patterns](https://rust-lang.github.io/rfcs/3637-guard-patterns.html) (see also [tracking issue](rust-lang#129967)). This PR is extracted from rust-lang#129996 with minor modifications. cc `@max-niederman`
rust-bors Bot
pushed a commit
that referenced
this pull request
Feb 27, 2026
Parse guard patterns This implements the parsing of [RFC3637 Guard Patterns](https://rust-lang.github.io/rfcs/3637-guard-patterns.html) (see also [tracking issue](#129967)). This PR is extracted from #129996 with minor modifications. cc `@max-niederman`
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Nov 14, 2026
…match-arm, r=mu001999
Under `guard_patterns` allow parenthesized guarded patterns in match arms
This PR renders `match $expr { ($pat if $expr) => $expr }` syntactically legal under unstable feature `guard_patterns`. [RFC 3637](rust-lang/rfcs#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 rust-lang#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 rust-lang#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)` if `guard_patterns` is 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_patterns` enabled" 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 in `compiler/rustc_ast_passes/src/feature_gate.rs` where we have access to the list of all enabled features (& to `Session` for querying `is_nightly_build`).
Part of rust-lang#129967.
<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Nov 14, 2026
…match-arm, r=mu001999
Under `guard_patterns` allow parenthesized guarded patterns in match arms
This PR renders `match $expr { ($pat if $expr) => $expr }` syntactically legal under unstable feature `guard_patterns`. [RFC 3637](rust-lang/rfcs#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 rust-lang#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 rust-lang#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)` if `guard_patterns` is 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_patterns` enabled" 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 in `compiler/rustc_ast_passes/src/feature_gate.rs` where we have access to the list of all enabled features (& to `Session` for querying `is_nightly_build`).
Part of rust-lang#129967.
<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Nov 15, 2026
…match-arm, r=mu001999
Under `guard_patterns` allow parenthesized guarded patterns in match arms
This PR renders `match $expr { ($pat if $expr) => $expr }` syntactically legal under unstable feature `guard_patterns`. [RFC 3637](rust-lang/rfcs#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 rust-lang#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 rust-lang#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)` if `guard_patterns` is 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_patterns` enabled" 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 in `compiler/rustc_ast_passes/src/feature_gate.rs` where we have access to the list of all enabled features (& to `Session` for querying `is_nightly_build`).
Part of rust-lang#129967.
<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
rust-bors Bot
pushed a commit
that referenced
this pull request
Nov 16, 2026
Rollup merge of #164465 - fmease:allow-paren-guarded-pat-in-match-arm, r=mu001999 Under `guard_patterns` allow parenthesized guarded patterns in match arms This PR renders `match $expr { ($pat if $expr) => $expr }` syntactically legal under unstable feature `guard_patterns`. [RFC 3637](rust-lang/rfcs#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)` if `guard_patterns` is 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_patterns` enabled" 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 in `compiler/rustc_ast_passes/src/feature_gate.rs` where we have access to the list of all enabled features (& to `Session` for querying `is_nightly_build`). Part of #129967. <sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
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 implements the parsing of RFC3637 Guard Patterns (see also tracking issue). This PR is extracted from #129996 with minor modifications.
cc @max-niederman