Skip to content

Macros do not suppress double_parens warnings anymore #15852

@bonzini

Description

@bonzini

Summary

Clippy does not suppress lints anymore within a macro.

Reproducer

Reduced testcase:

#[repr(transparent)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct InterruptMask(u32);
macro_rules! foo {
    ($a:expr, $b:expr, $c:expr, $d:expr) => {
        InterruptMask(((($a.union($b).union($c).union($d))).into_bits()) as u32)
    }
}

impl InterruptMask {
    pub const OE: InterruptMask = InterruptMask(1 << 10);
    pub const BE: InterruptMask = InterruptMask(1 << 9);
    pub const PE: InterruptMask = InterruptMask(1 << 8);
    pub const FE: InterruptMask = InterruptMask(1 << 7);
    pub const E: InterruptMask = foo!(Self::OE, Self::BE, Self::PE, Self::FE);
    pub const fn into_bits(self) -> u32 {
        self.0
    }
    #[must_use]
    pub const fn union(self, rhs: Self) -> Self {
        InterruptMask(self.0 | rhs.0)
    }
}

Expected result:

$ clippy-driver +nightly-2025-10-07 --crate-type rlib -D warnings --edition=2021 -C opt-level=2 -g  -D warnings f.rs
<no output>

Actual result:

$ clippy-driver +nightly --crate-type rlib -D warnings --edition=2021 -C opt-level=2 -g  -D warnings f.rs
error: unnecessary parentheses
  --> f.rs:6:24
   |
 6 |         InterruptMask(((($a.union($b).union($c).union($d))).into_bits()) as u32)
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove them: `($a.union($b).union($c).union($d))`
...
15 |     pub const E: InterruptMask = foo!(Self::OE, Self::BE, Self::PE, Self::FE);
   |                                  -------------------------------------------- in this macro invocation
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#double_parens
   = note: `-D clippy::double-parens` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::double_parens)]`
   = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error

Version

rustc 1.92.0-nightly (b6f0945e4 2025-10-08)
binary: rustc
commit-hash: b6f0945e4681bc4d2faa7c22c5f61dc36abf7dd2
commit-date: 2025-10-08
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.2

Additional Labels

No response

Metadata

Metadata

Assignees

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