rust-lang / rust-lang/rust-clippy

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

Open
#15,312 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug C-question I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the my_error wrapper example with disallowed_macros on the reported Rust version, then trace how the lint handles macro expansion and attribute spans. Done means the allowance on the wrapper affects the emitted tracing::error calls at the intended node, with regression coverage for the shown cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.