Skip to content

Macros that emit attributes do not trigger at the correct node in disallowed_macros #15312

@BatmanAoD

Description

@BatmanAoD

Description

I wanted to write a "wrapper" macro around tracing::error, then disallow tracing::error itself, but it seems I can't just put an allow in the "wrapper" macro itself. Here's a sort of "dummy" version of what I'm doing:

macro_rules! my_error {
    ($($args:tt)+) => {
        #[allow(clippy::disallowed_macros)]
        if <some logic> {
            tracing::error!(<some extra fields>, $($args)+);
        } else {
            tracing::error!($($args)+)
        }
    }
}

The allow seems to have absolutely no effect. Is there a way to do this correctly?

Version

rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: aarch64-apple-darwin
release: 1.88.0
LLVM version: 20.1.5

Additional Labels

@rustbot label +C-question

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-questionCategory: QuestionsI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions