Skip to content
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

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

Open
ada4a opened this issue Feb 8, 2025 · 0 comments · May be fixed by #136906
Open

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

ada4a opened this issue Feb 8, 2025 · 0 comments · May be fixed by #136906
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. L-unused_parens Lint: unused_parens T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ada4a
Copy link
Contributor

ada4a commented Feb 8, 2025

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))

@ada4a ada4a added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 8, 2025
@jieyouxu jieyouxu added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. L-unused_parens Lint: unused_parens labels Feb 8, 2025
@chenyukang chenyukang self-assigned this Feb 12, 2025
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. L-unused_parens Lint: unused_parens 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.

3 participants