Commit 9de3b8f
committed
Fix grammar for
We had documented that only numeric literals in patterns can be
prefixed by `-` (minus), but the Rust parser happily accepts a minus
ahead of all literals in patterns. E.g.:
```rust
match () {
-true | -false => (),
-'x' => (),
-b'x' => (),
-"x" => (),
-r"x" => (),
-br"x" => (),
-c"x" => (),
-cr"x" => (),
-1 => (),
-1.1 => (),
}
```
In the compiler, this happens in `Parser::parse_literal_maybe_minus`
and `Token::can_begin_literal_maybe_minus`.
Let's fix this by removing the `-`s from within `LiteralPattern` and
instead allowing `LiteralPattern` to be prefixed by an optional `-`.
This better matches how the `rustc` AST models this as compared with
the alternative of including the optional `-`s pervasively in the
`LiteralPattern` production.LiteralPattern regarding -
1 parent 048d75a commit 9de3b8f
1 file changed
+3
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
153 | | - | |
| 152 | + | |
| 153 | + | |
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| |||
0 commit comments