Incorrect error message when `decl_macro` macro refers to `macro_rules!` macro
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
#![feature(decl_macro)]
macro_rules! inner {
() => {}
}
macro outer() {
inner!();
}
outer!();
This code results in this confusing and completely incorrect error message:
error: cannot find macro `inner` in this scope
--> src/lib.rs:10:5
|
10 | inner!();
| ^^^^^ consider moving the definition of `inner` before this call
...
15 | outer!();
| -------- in this macro invocation
|
note: a macro with the same name exists, but it appears later
--> src/lib.rs:5:14
|
5 | macro_rules! inner {
| ^^^^^
= note: this error originates in the macro `outer` (in Nightly builds, run with -Z macro-backtrace for more info)
Obviously, the definition of inner doesn't "appear later" than the definition of outer. In fact, the problem has nothing to do with definition order. The real fix is to add use inner; anywhere after the definition of inner.
(As a side note, I don't know if this is the intended behavior of macros 2.0, or a bug / current limitation of the nightly feature)
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 by running the linked Rust Playground example on nightly and compare the diagnostic with the reported output. Trace the compiler's diagnostic and name-resolution handling for a decl_macro referring to a macro_rules! macro. Done means the error no longer incorrectly attributes the problem to definition order and instead explains the required import or actual limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100