1
Fork 0

Rollup merge of #88553 - theo-lw:issue-88276, r=estebank

Improve diagnostics for unary plus operators (#88276)

This pull request improves the diagnostics emitted on parsing a unary plus operator. See #88276.

Before:

```
error: expected expression, found `+`
 --> src/main.rs:2:13
  |
2 |     let x = +1;
  |             ^ expected expression
```

After:

```
error: leading `+` is not supported
 --> main.rs:2:13
  |
2 |     let x = +1;
  |             ^
  |             |
  |             unexpected `+`
  |             help: try removing the `+`
```
This commit is contained in:
Jack Huey 2021-09-08 12:24:16 -04:00 committed by GitHub
commit 77ac329a08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 105 additions and 6 deletions

View file

@ -586,6 +586,13 @@ impl Token {
self.is_non_raw_ident_where(|id| id.name.is_bool_lit())
}
pub fn is_numeric_lit(&self) -> bool {
matches!(
self.kind,
Literal(Lit { kind: LitKind::Integer, .. }) | Literal(Lit { kind: LitKind::Float, .. })
)
}
/// Returns `true` if the token is a non-raw identifier for which `pred` holds.
pub fn is_non_raw_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool {
match self.ident() {