Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pnkfelix opened this issue Nov 24, 2020 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pnkfelix
Copy link
Member

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)

@pnkfelix pnkfelix added C-bug Category: This is a bug. C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Nov 24, 2020
@jyn514 jyn514 added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Nov 24, 2020
@joshtriplett
Copy link
Member

#121130 fixes this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants