Commit 17aa1bd
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
#[cfg(any())]
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 17aa1bd
1 file changed
+4
-4
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 | | |
157 | 157 | | |
158 | | - | |
| 158 | + | |
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| |||
0 commit comments