Skip to content

unused_parens lint should not complain about parens injected by macros #22451

Closed
@pnkfelix

Description

@pnkfelix

The following code fails to compile:

#![deny(unused_parens)]

macro_rules! add1_block {
    ($e:expr) => {
        { let val = 1; $e + val }
    }
}

macro_rules! add1_paren_block {
    ($e:expr) => {
        ({ let val = 1; $e + val })
    }
}

fn main() {
    let w = add1_block!(2);
    let x = { add1_block!(3) as u64 };
    let y = add1_paren_block!(4);
    let z = { add1_paren_block!(5) as u64 };

    println!("w: {} x: {} y: {} z: {}", w, x, y, z);
}

The parentheses in the macro are, in general, not unnecessary (for the explanation of why they are necessary, see #22450).

In general, it is silly for lint to be trying to fix style errors of this sort within macros. The place for such stylistic judgement, IMO, is within the original source code, not within macros.

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-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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