Skip to content

unused_parens false positive on braced macro calls #78747

Closed
@LunaBorowska

Description

@LunaBorowska

I tried this code:

macro_rules! x {
    {} => { "q" };
}

fn f() -> String {
    (x! {}.to_string())
}

fn main() {}

I expected to see this happen: No warning about unnecessary parens

Instead, this happened: A warning about unnecessary parens suggesting to remove parens. Attempting to actually follow the advice causes an error.

warning: unnecessary parentheses around block return value
 --> src/main.rs:6:5
  |
6 |     (x! {}.to_string())
  |     ^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
  |
  = note: `#[warn(unused_parens)]` on by default

This can be worked around by using x!().to_string or (x! {}).to_string() instead, however this shouldn't be necessary as the original code is fine.

This happens since Rust 1.42.

Meta

rustc --version --verbose:

rustc 1.47.0 (18bf6b4f0 2020-10-07)
binary: rustc
commit-hash: 18bf6b4f01a6feaf7259ba7cdae58031af1b7b39
commit-date: 2020-10-07
host: x86_64-unknown-linux-gnu
release: 1.47.0
LLVM version: 11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.P-mediumMedium priorityregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions