Skip to content

false-negative unused_parens in closures consisting of just one expression #136741

Closed
@ada4a

Description

@ada4a
Contributor

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 emitted

Rationale 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.5

Anything else?

Also tested on the latest nightly (rustc 1.86.0-nightly (a9e7b3048 2025-02-07))

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Feb 8, 2025
added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
on Feb 8, 2025
self-assigned this
on Feb 12, 2025
added
L-false-negativeLint: False negative (should have fired but didn't).
A-closuresArea: Closures (`|…| { … }`)
on Jun 17, 2025
added a commit that references this issue on Jul 10, 2025

Rollup merge of rust-lang#136906 - chenyukang:yukang-fix-136741-closu…

a0c7887
added a commit that references this issue on Jul 10, 2025
936033a
added a commit that references this issue on Jul 12, 2025

Rollup merge of rust-lang#136906 - chenyukang:yukang-fix-136741-closu…

a2b2f71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.L-false-negativeLint: False negative (should have fired but didn't).L-unused_parensLint: unused_parensT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @chenyukang@fmease@jieyouxu@ada4a

    Issue actions

      false-negative `unused_parens` in closures consisting of just one expression · Issue #136741 · rust-lang/rust