Merge pull request #1826 from rust-lang/TC/parse-repeats-without-regex
Parse optionals and repeats without regexes
diff --git a/src/patterns.md b/src/patterns.md
index e3a5c18..60cfb21 100644
--- a/src/patterns.md
+++ b/src/patterns.md
@@ -139,23 +139,11 @@
r[patterns.literal.syntax]
```grammar,patterns
-LiteralPattern ->
- `true` | `false`
- | CHAR_LITERAL
- | BYTE_LITERAL
- | STRING_LITERAL
- | RAW_STRING_LITERAL
- | BYTE_STRING_LITERAL
- | RAW_BYTE_STRING_LITERAL
- | C_STRING_LITERAL
- | RAW_C_STRING_LITERAL
- | `-`? INTEGER_LITERAL
- | `-`? FLOAT_LITERAL
+LiteralPattern -> `-`? LiteralExpression
```
r[patterns.literal.intro]
-_Literal patterns_ match exactly the same value as what is created by the literal.
-Since negative numbers are not [literals], literal patterns also accept an optional minus sign before the literal, which acts like the negation operator.
+_Literal patterns_ match exactly the same value as what is created by the literal. Since negative numbers are not [literals], literals in patterns may be prefixed by an optional minus sign, which acts like the negation operator.
> [!WARNING]
> C string and raw C string literals are accepted in literal patterns, but `&CStr` doesn't implement structural equality (`#[derive(Eq, PartialEq)]`) and therefore any such `match` on a `&CStr` will be rejected with a type error.
@@ -497,10 +485,7 @@
RangePatternBound `...` RangePatternBound
RangePatternBound ->
- CHAR_LITERAL
- | BYTE_LITERAL
- | `-`? INTEGER_LITERAL
- | `-`? FLOAT_LITERAL
+ LiteralPattern
| PathExpression
```
@@ -553,7 +538,11 @@
* A character, byte, integer, or float literal.
* A `-` followed by an integer or float literal.
-* A [path]
+* A [path].
+
+> [!NOTE]
+>
+> We syntactically accept more than this for a *[RangePatternBound]*. We later reject the other things semantically.
r[patterns.range.constraint-bound-path]
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.