False positive unused_braces
Open
Nobody has claimed this yet.
A-diagnostics
A-lints
C-bug
D-invalid-suggestion
L-false-positive
L-unused_braces
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the Rust code in the report and inspect the rustc unused_braces lint and its suggestion output. The fix is done when the reported example receives a suggestion that compiles, with a regression test covering this if return case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100