Skip to content

False positive unused_braces #141783

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

Open
matthiaskrgr opened this issue May 30, 2025 · 1 comment · May be fixed by #141987
Open

False positive unused_braces #141783

matthiaskrgr opened this issue May 30, 2025 · 1 comment · May be fixed by #141987
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-false-positive Lint: False positive (should not have fired). L-unused_braces Lint: unused_braces T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented May 30, 2025

I tried this code:

#[allow(unreachable_code)]
#[warn(unused_braces)]

fn main() {
    if return { return } { return } else { return }
}
warning: unnecessary braces around `return` value
 --> a.rs:3:15
  |
3 |     if return { return } { return } else { return }
  |               ^^      ^^
  |
  = note: `#[warn(unused_braces)]` on by default
help: remove these braces
  |
3 -     if return { return } { return } else { return }
3 +     if return return { return } else { return }
  |

warning: 1 warning emitted

the suggestion does not compile:

#[allow(unreachable_code)]
#[warn(unused_braces)]

fn main() {
    if return return { return } else { return }
}

=>

error: this `if` expression is missing a block after the condition
 --> a.rs:5:5
  |
5 |     if return return { return } else { return }
  |     ^^
  |
help: add a block here
 --> a.rs:5:32
  |
5 |     if return return { return } else { return }
  |                                ^

warning: unnecessary braces around `return` value
 --> a.rs:5:22
  |
5 |     if return return { return } else { return }
  |                      ^^      ^^
  |
note: the lint level is defined here
 --> a.rs:2:8
  |
2 | #[warn(unused_braces)]
  |        ^^^^^^^^^^^^^
help: remove these braces
  |
5 -     if return return { return } else { return }
5 +     if return return return else { return }
  |

error: aborting due to 1 previous error; 1 warning emitted
rustc 1.89.0-nightly (1bbd62e54 2025-05-29)
binary: rustc
commit-hash: 1bbd62e547ba5cc08ccb44c27def3d33195d2dd5
commit-date: 2025-05-29
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label May 30, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 30, 2025
@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels May 30, 2025
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 30, 2025
@jieyouxu jieyouxu added L-unused_braces Lint: unused_braces L-false-positive Lint: False positive (should not have fired). A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 30, 2025
@Noratrieb Noratrieb changed the title FP unused_braces False positive unused_braces May 30, 2025
@ChAoSUnItY
Copy link
Contributor

@rustbot claim

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 A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-false-positive Lint: False positive (should not have fired). L-unused_braces Lint: unused_braces 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.

4 participants