Skip to content

Unary plus gives suboptimal parse error #88276

Closed
@CAD97

Description

@CAD97

Given the following code:

fn main() {
    let x = +1;
}

The current output is:

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

Ideally, if we want to continue rejecting unary plus on number literals, the parser should recover the unexpected unary plus, and the output should look somewhat like:

error: leading `+` on numeric literals is not supported
 --> src/main.rs:2:13
  |
2 |     let x = +1;
  |             ^ unexpected `+`
  = help: remove it; the unsigned literal is positive and may still be used for a signed type

Tested on 1.56.0-nightly (2021-08-22 af14075)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions