Skip to content

Incorrect error message when decl_macro macro refers to macro_rules! macro #148414

@max-kamps

Description

@max-kamps

Playground link

#![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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions