Skip to content

Unfound macro diagnostic could detect a later definition and suggest moving it #79385

Open
@pnkfelix

Description

@pnkfelix

I tried this code:

mod a {
    pub fn f() {
        hello!("from a::f"); 
    }
}

macro_rules! hello {
    ($x:expr) => {
        println!("Hello {}!", $x);
    }
}

fn main() {
    a::f();
    hello!("from main");
}

I expected to see this happen:

"You have a use of an undefined macro. I found a macro definition with the same name later in the module hierarchy. I suggest you move the macro definition so that it appears before the mod a in the module hierarchy, like so: ..."

Instead, this happened:

error: cannot find macro `hello` in this scope
 --> src/main.rs:3:9
  |
3 |         hello!("from a::f"); 
  |         ^^^^^
  |
  = help: have you added the `#[macro_use]` on the module/import?

error: aborting due to previous error

(where the help here does not actually address the problem.)

Version info

Nightly channel

Build using the Nightly version: 1.50.0-nightly

(2020-11-23 d9a105f)

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, ..)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions