Skip to content

Should importing a #[macro_export] macro_rules! macro trigger unused_imports? #147823

@SabrinaJewson

Description

@SabrinaJewson

I tried this code:

#[macro_export]
macro_rules! owo {
    () => {};
}
mod m {
    use crate::owo;
    owo!();
}

On stable, cargo check completes successfully. On Nightly, it produces a warning:

warning: unused import: `crate::owo`
 --> src/lib.rs:6:9
  |
6 |     use crate::owo;
  |         ^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

Nightly is correct in the sense that the import is, in fact, unnecessary, and the code builds with or without it. But I’m not sure whether this is a bug or not. I always put the import in because I like to think about modules and don’t like to think about the arcane macro_rules! scoping rules, but given that I can’t disable those rules this might be a losing battle…

Meta

rustc --version --verbose:

rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: x86_64-unknown-linux-gnu
release: 1.90.0
LLVM version: 20.1.8

rustc +nightly --version --verbose:

rustc 1.92.0-nightly (53a741fc4 2025-10-16)
binary: rustc
commit-hash: 53a741fc4b8cf2d8e7b1b2336ed8edf889db84f4
commit-date: 2025-10-16
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-decl-macros-1-2Area: Declarative macros 1.2A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-discussionCategory: Discussion or questions that doesn't represent real issues.L-unused_importsLint: unused_importsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions