Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

diagnostics when parsing { {10} - 1 } is confusing #88701

Closed
BoxyUwU opened this issue Sep 6, 2021 · 1 comment · Fixed by #88757
Closed

diagnostics when parsing { {10} - 1 } is confusing #88701

BoxyUwU opened this issue Sep 6, 2021 · 1 comment · Fixed by #88757
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

@BoxyUwU
Copy link
Member

BoxyUwU commented Sep 6, 2021

Given the following code:

#![allow(unused_braces)]

fn main() {
    let _: usize = { {10} - 1 };
}

The current output is:

error[E0308]: mismatched types
 --> src/main.rs:4:23
  |
4 |     let _: usize = { {10} - 1 };
  |                       ^^ expected `()`, found integer

error[E0600]: cannot apply unary operator `-` to type `usize`
 --> src/main.rs:4:27
  |
4 |     let _: usize = { {10} - 1 };
  |                           ^^^
  |                           |
  |                           cannot apply unary operator `-`
  |                           help: you may have meant the maximum value of `usize`: `usize::MAX`
  |
  = note: unsigned values cannot be negated

Ideally this would give the same diagnostics as {10} + 1 gives:

error: expected expression, found `+`
 --> src/main.rs:4:27
  |
4 |     let _: usize = { {10} + 1 };
  |                           ^ expected expression
  |
help: parentheses are required to parse this as an expression
  |
4 |     let _: usize = { ({10}) + 1 };
  |                      +    +

error[E0308]: mismatched types
 --> src/main.rs:4:23
  |
4 |     let _: usize = { {10} + 1 };
  |                       ^^ expected `()`, found integer
@BoxyUwU BoxyUwU 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 Sep 6, 2021
@andrewhickman
Copy link
Contributor

@rustbot claim

workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 11, 2021
Suggest wapping expr in parentheses on invalid unary negation

Fixes rust-lang#88701
@bors bors closed this as completed in d6ce326 Sep 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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

Successfully merging a pull request may close this issue.

2 participants