Skip to content

crate_in_macro_def lints on a macro use #15620

@hkBst

Description

@hkBst

Summary

Running clippy on rustc, I got this warning:

warning: `crate` references the macro call's crate
    --> compiler/rustc_middle/src/query/mod.rs:1430:53
     |
1430 |     query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
     |                                                     ^^^^^ help: to reference the macro definition's crate, use: `$crate`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#crate_in_macro_def
     = note: `-W clippy::crate-in-macro-def` implied by `-W clippy::suspicious`
     = help: to override `-W clippy::suspicious` add `#[allow(clippy::crate_in_macro_def)]`

Following this advice leads to all kinds of compiler errors. I don't understand this code well enough to understand why it is wrong, but looking at the lint docs it says:

Checks for usage of crate as opposed to $crate in a macro definition.

This hit is for a procedural macro call, not a macro definition.

Lint Name

crate_in_macro_def

Reproducer

run clippy on rustc

Version

rustc 1.91.0-nightly (af00ff2ce 2025-09-04)
binary: rustc
commit-hash: af00ff2ce62b6617ed19305ae39e135ac71d0b22
commit-date: 2025-09-04
host: aarch64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0

Additional Labels

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions