Skip to content

Fix grammar for RangePatternBound regarding literals #1825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2025

Conversation

traviscross
Copy link
Contributor

The compiler, in parsing, accepts many more kinds of literals in the bound of a range pattern than what we had documented, and as with PatternWithoutRange, the parser allows each of these literals to be prefixed with -. E.g.

#[cfg(any())]
match () {
    ..-true | ..-false => (),
    ..-'x' => (),
    ..-b'x' => (),
    ..-"x" => (),
    ..-r"x" => (),
    ..-br"x" => (),
    ..-c"x" => (),
    ..-cr"x" => (),
    ..-1 => (),
    ..-1.1 => (),
}

Let's fix this by adjusting the RangePatternBound production to use LiteralPattern. In a separate PR, we've adjusted LiteralPattern to allow for a minus sign ahead of all literal expressions.

To help the reader, let's also add a note that highlights that what we discuss later as being allowed semantically is more restrictive than what we allow in parsing (and therefore in the grammar).

cc @ehuss

@traviscross traviscross force-pushed the TC/fix-range-pattern-bound branch from bc4573a to 7a9806a Compare May 15, 2025 07:56
The compiler, in parsing, accepts many more kinds of literals in the
bound of a range pattern than what we had documented, and as with
`PatternWithoutRange`, the parser allows each of these literals to be
prefixed with `-`.  E.g.

```rust
#[cfg(any())]
match () {
    ..-true | ..-false => (),
    ..-'x' => (),
    ..-b'x' => (),
    ..-"x" => (),
    ..-r"x" => (),
    ..-br"x" => (),
    ..-c"x" => (),
    ..-cr"x" => (),
    ..-1 => (),
    ..-1.1 => (),
}
```

Let's fix this by adjusting the `RangePatternBound` production to use
`LiteralPattern`.  In a separate PR, we've adjusted `LiteralPattern`
to allow for a minus sign ahead of all literal expressions.

To help the reader, let's also add a note that highlights that what we
discuss later as being allowed semantically is more restrictive than
what we allow in parsing (and therefore in the grammar).
@traviscross traviscross force-pushed the TC/fix-range-pattern-bound branch from 7a9806a to 4b4ae59 Compare May 15, 2025 08:02
@traviscross traviscross marked this pull request as ready for review May 15, 2025 08:04
@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label May 15, 2025
Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

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

Thanks!

@ehuss ehuss added this pull request to the merge queue May 15, 2025
Merged via the queue into master with commit 3a5fb6a May 15, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: The marked PR is awaiting review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants