Commit bb6790b
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 defining `LiteralPattern` as a `LiteralExpression`
optionally prefixed by the minus sign. This better matches how the
`rustc` AST models this.LiteralPattern regarding -
1 parent 048d75a commit bb6790b
1 file changed
+2
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 142 | + | |
154 | 143 | | |
155 | 144 | | |
156 | 145 | | |
157 | 146 | | |
158 | | - | |
| 147 | + | |
159 | 148 | | |
160 | 149 | | |
161 | 150 | | |
| |||
0 commit comments