rust-lang / rust-lang/rust-clippy

A tuple enclosed in paren results in `double_parens` even if `unused_parens` is disabled.

Open
#10,558 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

When I disable unused_parens, clippy stops complaining about this code as expected:

match (a + b) {
    _ => todo!(),
}

However, when the expression is a tuple like in the code below, clippy instead starts saying this is double_parens.

match ((a, b)) {
    _ => todo!(),
}

I mark this issue as False Positive because:

  • I feel some inconsistency here. To write a consistent code with the first code, I have to disable not only unused_parens but also double_parens, making clippy now overlook (((3))) + 4, return ((0)), etc.

  • Just by seeing the examples shown in the documentation of double_parens, I think the original intention of the lint is not to detect the case shown in this issue.

Lint Name

double_parens

Reproducer

Source Code

fn main() {
    let a = 3;
    let b = 4;
    match ((a, b)) {
        _ => todo!(),
    }
}

Actual Output 1 (without --allow unused_parens)

$ RUSTFLAGS= cargo clippy

warning: unnecessary parentheses around `match` scrutinee expression
 --> src/main.rs:4:11
  |
4 |     match ((a, b)) {
  |           ^      ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
4 -     match ((a, b)) {
4 +     match (a, b) {
  |

warning: consider removing unnecessary double parentheses
 --> src/main.rs:4:11
  |
4 |     match ((a, b)) {
  |           ^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#double_parens
  = note: `#[warn(clippy::double_parens)]` on by default

Actual Output 2 (with --allow unused_parens)

$ RUSTFLAGS='--allow unused_parens' cargo clippy

warning: consider removing unnecessary double parentheses
 --> src/main.rs:4:11
  |
4 |     match ((a, b)) {
  |           ^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#double_parens
  = note: `#[warn(clippy::double_parens)]` on by default

Expected Output

$ RUSTFLAGS='--allow unused_parens' cargo clippy

(nothing shown)
Version
rustc 1.68.0 (2c8cc3432 2023-03-06)
binary: rustc
commit-hash: 2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74
commit-date: 2023-03-06
host: aarch64-apple-darwin
release: 1.68.0
LLVM version: 15.0.6
Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided match-expression reproducer with cargo clippy, both with and without --allow unused_parens. Inspect the double_parens and unused_parens lint behavior; done means the tuple case produces no warning when unused_parens is allowed without suppressing unrelated double-parentheses warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.