Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pnkfelix opened this issue Feb 17, 2015 · 4 comments
Closed
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pnkfelix
Copy link
Member

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.

@steveklabnik steveklabnik added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Feb 17, 2015
@steveklabnik
Copy link
Member

Triage: no change.

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 22, 2017
@steveklabnik
Copy link
Member

Triage: no change

@jonas-schievink jonas-schievink added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 18, 2020
@camsteffen
Copy link
Contributor

Fixed by #66983

@Dylan-DPC
Copy link
Member

Closing this as fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants