Skip to content

False positive for unused_parens in a return #131989

Closed
@kawadakk

Description

@kawadakk

Code

fn foo() {
    return (_ = 42);
}

Current output

warning: unnecessary parentheses around `return` value
 --> src/lib.rs:2:12
  |
2 |     return (_ = 42);
  |            ^      ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
2 -     return (_ = 42);
2 +     return _ = 42;
  |

Desired output

No output, since removing the parentheses results in a compile error:

error: expected one of `;`, `}`, or an operator, found reserved identifier `_`
 --> src/lib.rs:2:12
  |
2 |     return _ = 42;
  |            ^ expected one of `;`, `}`, or an operator

Rationale and extra context

No response

Other cases

No response

Rust Version

$ rustc -vV
rustc 1.84.0-nightly (662180b34 2024-10-20)
binary: rustc
commit-hash: 662180b34d95f72d05b7c467b0baf4d23d36b1e1
commit-date: 2024-10-20
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.L-false-positiveLint: False positive (should not have fired).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

No branches or pull requests

Issue actions