Skip to content

Commit bf89144

Browse files
authored
Merge pull request #1824 from rust-lang/TC/fix-literal-pattern
Fix grammar for `LiteralPattern` regarding `-`
2 parents 048d75a + 1fc4b67 commit bf89144

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/patterns.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,11 @@ r[patterns.literal]
139139

140140
r[patterns.literal.syntax]
141141
```grammar,patterns
142-
LiteralPattern ->
143-
`true` | `false`
144-
| CHAR_LITERAL
145-
| BYTE_LITERAL
146-
| STRING_LITERAL
147-
| RAW_STRING_LITERAL
148-
| BYTE_STRING_LITERAL
149-
| RAW_BYTE_STRING_LITERAL
150-
| C_STRING_LITERAL
151-
| RAW_C_STRING_LITERAL
152-
| `-`? INTEGER_LITERAL
153-
| `-`? FLOAT_LITERAL
142+
LiteralPattern -> `-`? LiteralExpression
154143
```
155144

156145
r[patterns.literal.intro]
157-
_Literal patterns_ match exactly the same value as what is created by the literal.
158-
Since negative numbers are not [literals], literal patterns also accept an optional minus sign before the literal, which acts like the negation operator.
146+
_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.
159147

160148
> [!WARNING]
161149
> 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.

0 commit comments

Comments
 (0)