Skip to content

Commit bc4573a

Browse files
committed
Fix grammar for RangePatternBound regarding literals
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).
1 parent 048d75a commit bc4573a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/patterns.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,7 @@ ObsoleteRangePattern ->
497497
RangePatternBound `...` RangePatternBound
498498
499499
RangePatternBound ->
500-
CHAR_LITERAL
501-
| BYTE_LITERAL
502-
| `-`? INTEGER_LITERAL
503-
| `-`? FLOAT_LITERAL
500+
LiteralPattern
504501
| PathExpression
505502
```
506503

@@ -553,7 +550,11 @@ A bound is written as one of:
553550

554551
* A character, byte, integer, or float literal.
555552
* A `-` followed by an integer or float literal.
556-
* A [path]
553+
* A [path].
554+
555+
> [!NOTE]
556+
>
557+
> The Rust parser, and therefore the grammar, accepts more than this for a range bound in a pattern, but these other things are rejected after parsing.
557558
558559
r[patterns.range.constraint-bound-path]
559560
If a bound is written as a path, after macro resolution, the path must resolve to a constant item of the type `char`, an integer type, or a float type.

0 commit comments

Comments
 (0)