Skip to content

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

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

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Sep 6, 2021
  2. andrewhickman commented on Sep 7, 2021

    @andrewhickman
    Contributor

    @rustbot claim

  3. added a commit that references this issue on Sep 11, 2021
    08cbb7d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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