Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Document macro_use shadow restriction

Open
#2,207 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
documentation

Research direction

Start with the provided macro_rules!/macro_use example and the diagnostic's reference to RFC 1560. Locate the Rust Reference section covering macro_use and document the applicable shadowing restriction, including whether macro-expanded attributes are covered; done when the example's behavior and rule are clearly explained.

Written by the indexing model from the issue text.

Description

A-macros

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.

Dominant language
Rust
Stars
1.6k
Forks
609
Avg merge
1d 4h
Merged PRs (30d)
7

Getting set up

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.

More from rust-lang/reference

All issues in rust-lang/reference

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.