Skip to content

Document macro_use shadow restriction #2207

Open

Description

@ehuss

There seems to be a restriction that macro_use cannot shadow a macro_use macro when expanded from within a macro_rules macro.

#[macro_use(foo)] extern crate m;

macro_rules! m1 { () => {
    #[macro_use(foo)] //~ ERROR `foo` is already in scope
    extern crate m as _;
}}
m1!();

emits:

error: `foo` is already in scope
  ╭▸ src/lib.rs:4:17
  │
4 │     #[macro_use(foo)] //~ ERROR `foo` is already in scope
  │                 ━━━
  ‡
7 │ m1!();
  │ ───── in this macro invocation
  │
  ├ note: macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)
  ╰ note: this error originates in the macro `m1` (in Nightly builds, run with -Z macro-backtrace for more info)

I couldn't find a rule (or combination of rules) that would cover this situation.

Activity

  1. petrochenkov commented on Mar 17, 2026

    @petrochenkov
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions