Open
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
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Category: This is a bug.Diagnostics: A structured suggestion resulting in incorrect code.Lint: False positive (should not have fired).Lint: unused_bracesRelevant to the compiler team, which will review and decide on the PR/issue.