Skip to content

Confusing "warning: unnecessary parentheses" in macro #16224

@spirali

Description

@spirali

Summary

In the following code, code compiles but the clippy warns about "unnecessary parentheses". When the parentheses are removed, the code does not compile.

Reproducer

Code:

#[allow(dead_code)]
enum Response {
    A(u32),
    B(u32),
}

macro_rules! call {
    ($matcher:pat $(=> $result:expr)?) => {
            match test() {
                $matcher => Result::Ok(($($result),*)),
                _ => Result::Err("No match".to_string()),
            }
    };
}

fn test() -> Response {
    Response::A(123)
}

fn main() {
    let _ = call!(Response::A(_));
    let _ = call!(Response::B(value) => value);
}

Current output:

warning: unnecessary parentheses
  --> src/main.rs:10:40
   |
10 |                 $matcher => Result::Ok(($($result),*)),
   |                                        ^^^^^^^^^^^^^^ help: remove them: `value`
...
22 |     let _ = call!(Response::B(value) => value);
   |             ---------------------------------- in this macro invocation
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#double_parens
   = note: `#[warn(clippy::double_parens)]` on by default
   = note: this warning originates in the macro `call` (in Nightly builds, run with -Z macro-backtrace for more info)

Desired output:

No warning or more clear warning what I should do.

When parantheses are removed then:

error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied
   --> src/main.rs:11:29
    |
 11 |                 $matcher => Result::Ok($($result)*),
    |                             ^^^^^^^^^^------------- argument #1 is missing
...
 22 |     let _ = call!(Response::A(_));
    |             --------------------- in this macro invocation
    |

Version

rustc 1.92.0 (ded5c06cf 2025-12-08)
binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.92.0
LLVM version: 21.1.3

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions