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

"Unnecessary" braces have an influence #72783

Open
vandenheuvel opened this issue May 30, 2020 · 3 comments
Open

"Unnecessary" braces have an influence #72783

vandenheuvel opened this issue May 30, 2020 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@vandenheuvel
Copy link
Contributor

vandenheuvel commented May 30, 2020

On 1.45.0-nightly (2020-05-29 4bd32c98047a809ba5fd)

fn f() -> usize {
    {1usize} - 1usize
}

Intuitively, I would expect these braces to be redundant and also have no influence, but they do. The compiler expects a () type and then considers the minus sign a unary operator.

warning: unnecessary braces around block return value
 --> src/lib.rs:6:5
  |
6 |     {1usize} - 1usize
  |     ^^^^^^^^ help: remove these braces
  |
  = note: `#[warn(unused_braces)]` on by default

error[E0308]: mismatched types
 --> src/lib.rs:6:6
  |
6 |     {1usize} - 1usize
  |      ^^^^^^ expected `()`, found `usize`

error[E0600]: cannot apply unary operator `-` to type `usize`
 --> src/lib.rs:6:14
  |
6 |     {1usize} - 1usize
  |              ^^^^^^^^ cannot apply unary operator `-`
  |
  = note: unsigned values cannot be negated

It seems to me that either the error message about the braces being redundant is incorrect or misleading, or something more nefarious seems to be going on with scopes, expressions, etc.

@vandenheuvel vandenheuvel added the C-bug Category: This is a bug. label May 30, 2020
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels May 30, 2020
@RalfJung
Copy link
Member

RalfJung commented Jun 2, 2020

Potentially related: #59975

@vandenheuvel
Copy link
Contributor Author

vandenheuvel commented Jun 14, 2021

Verified that this bug is still present as of today.

1 similar comment
@vandenheuvel
Copy link
Contributor Author

Verified that this bug is still present as of today.

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 C-enhancement Category: An issue proposing an enhancement or a PR with one. 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