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

hygiene: cannot find macro foo! in this scope #63685

Closed
tesuji opened this issue Aug 18, 2019 · 5 comments · Fixed by #63717
Closed

hygiene: cannot find macro foo! in this scope #63685

tesuji opened this issue Aug 18, 2019 · 5 comments · Fixed by #63717
Assignees
Labels
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-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tesuji
Copy link
Contributor

tesuji commented Aug 18, 2019

This code (playpen) compiles on stable but not on nightly and beta:

macro_rules! foo {
    () => {
        "foo"
    };
}

macro_rules! bar {
    () => {
        foo!()
    };
}

fn main() {
    println!(bar!());
}

Standard Error

   Compiling playground v0.0.1 (/playground)
error: cannot find macro `foo!` in this scope
 --> src/main.rs:9:9
  |
9 |         foo!()
  |         ^^^

warning: unused macro definition
 --> src/main.rs:1:1
  |
1 | / macro_rules! foo {
2 | |     () => {
3 | |         "foo"
4 | |     };
5 | | }
  | |_^
  |
  = note: `#[warn(unused_macros)]` on by default

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Edit: Removed concat! macro

Originally posted by @lzutao in #63460 (comment)

@tesuji

This comment has been minimized.

@rustbot rustbot added 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-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 18, 2019
@petrochenkov petrochenkov added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label Aug 18, 2019
@petrochenkov petrochenkov self-assigned this Aug 18, 2019
@tesuji

This comment has been minimized.

@petrochenkov
Copy link
Contributor

This is a regression from #63114 (cc @matthewjasper).
Slightly more minimized reproduction will look like this:

macro_rules! foo {
    () => {
        "foo"
    };
}

macro_rules! bar {
    () => {
        foo!()
    };
}

fn main() {
    format_args!(bar!()); // ERROR, `foo` is not found, happens because `format_args` is opaque now
}

format_args performs eager expansion on its arguments and hygienic context of foo produced by such expansion looks like it was produced by the opaque format_args for some reason, so it's resolved at format_args' definition site.

It maybe either some issue with hygiene infra interacting with eager expansion, but it also may be caused by incorrect spans produced by format_args.

@petrochenkov
Copy link
Contributor

petrochenkov commented Aug 18, 2019

(I'm currently looking into the details.)

UPD: I have a fix locally, will submit tomorrow.

@petrochenkov
Copy link
Contributor

Fixed in #63717.

@bors bors closed this as completed in 7043696 Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants