Skip to content

Unary plus gives suboptimal parse error #88276

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
CAD97 opened this issue Aug 24, 2021 · 2 comments
Closed

Unary plus gives suboptimal parse error #88276

CAD97 opened this issue Aug 24, 2021 · 2 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CAD97
Copy link
Contributor

CAD97 commented Aug 24, 2021

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)

@CAD97 CAD97 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 24, 2021
@theo-lw
Copy link
Contributor

theo-lw commented Sep 1, 2021

Working on this @rustbot claim.

jackh726 added a commit to jackh726/rust that referenced this issue Sep 8, 2021
Improve diagnostics for unary plus operators (rust-lang#88276)

This pull request improves the diagnostics emitted on parsing a unary plus operator. See rust-lang#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 `+`
```
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 8, 2021
Rollup of 9 pull requests

Successful merges:

 - rust-lang#86263 (Rustdoc: Report Layout of enum variants)
 - rust-lang#88541 (Add regression test for rust-lang#74400)
 - rust-lang#88553 (Improve diagnostics for unary plus operators (rust-lang#88276))
 - rust-lang#88594 (More symbolic doc aliases)
 - rust-lang#88648 (Correct “copies” to “moves” in `<Option<T> as From<T>>::from` doc, and other copyediting)
 - rust-lang#88691 (Add a regression test for rust-lang#88649)
 - rust-lang#88694 (Drop 1.56 stabilizations from 1.55 release notes)
 - rust-lang#88712 (Fix docs for `uX::checked_next_multiple_of`)
 - rust-lang#88726 (Fix typo in `const_generics` replaced with `adt_const_params` note)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@camelid
Copy link
Member

camelid commented Sep 8, 2021

Closing now that #88553 has been merged.

@camelid camelid closed this as completed Sep 8, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants