-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Closed
Copy link
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.L-false-negativeLint: False negative (should have fired but didn't).Lint: False negative (should have fired but didn't).L-unused_parensLint: unused_parensLint: unused_parensT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
pub fn main() {
let _ = || (0 == 0);
}Current output
<compiles without warnings>Desired output
warning: unnecessary parentheses around block return value
--> foo.rs:2:16
|
2 | (0 == 0)
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
2 - let _ = || (0 == 0);
2 + let _ = || 0 == 0;
|
warning: 1 warning emittedRationale and extra context
Note that the code above is really the minimal example, where not having any delimiters could actually be confusing (but one could use braces). What I had initially is a closure inside an iterator combinator, something like this:
let _ = (0..).find(|n| (n % 2 == 0));Other cases
pub fn main() {
let _ = || {
_ = 0;
(0 == 0)
};
}Rust Version
rustc 1.84.1 (e71f9a9a9 2025-01-27)
binary: rustc
commit-hash: e71f9a9a98b0faf423844bf0ba7438f29dc27d58
commit-date: 2025-01-27
host: x86_64-unknown-linux-gnu
release: 1.84.1
LLVM version: 19.1.5Anything else?
Also tested on the latest nightly (rustc 1.86.0-nightly (a9e7b3048 2025-02-07))
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.L-false-negativeLint: False negative (should have fired but didn't).Lint: False negative (should have fired but didn't).L-unused_parensLint: unused_parensLint: unused_parensT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.