Skip to content

Document macro_use shadow restriction #2207

@ehuss

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    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