rust-lang / rust-lang/reference
Document macro_use shadow restriction
Open
Nobody has claimed this yet.
A-macros
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 607
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
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.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100