Skip to content

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

Closed
@BoxyUwU

Description

@BoxyUwU

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

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