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

Macro-expanded macro definitions are not resolved #2233

Closed
matthewjasper opened this issue May 22, 2023 · 1 comment · Fixed by #2541
Closed

Macro-expanded macro definitions are not resolved #2233

matthewjasper opened this issue May 22, 2023 · 1 comment · Fixed by #2541

Comments

@matthewjasper
Copy link
Contributor

I tried this code:

macro_rules! one {
    () => {
        macro_rules! two {
            () => {
                
            }
        }
    }
}

one!();
two!();

I expected to see this happen: compiles

Instead, this happened:

<source>:12:1: error: unknown macro: [two]
   12 | two!();
      | ^~~

Meta

  • What version of Rust GCC were you using, git sha if possible.
    gccrs (Compiler-Explorer-Build-gcc-c7b7e297ea4b688ef9fb51a8aee2a8b2af39ac1c-binutils-2.40) 13.0.1 20230417 (experimental)
@CohenArthur
Copy link
Member

rust-lang/rfcs#1560 (comment)

mod a {
    macro_rules! m { () => {
        macro_rules! m { () => {
            fn f() {}
        } }
    } }
}
mod b {
    use a::*;
    c::m! {} // If we expand this first, it would resolve to `a::m!` and then
             // `b::m!` would expand to `fn f() {}`, ensuring correctness.
}
mod c {
    use a::*;
    b::m! {} // If we expand this first, it would resolve to `a::m!` and then
             // `c::m!` would expand to `fn f() {}`, ensuring correctness.
}

One way to go about it is to run the Early name resolver and expander in a fixed point, and store errors in a container instead of emitting them immediately. Then, once the fixed point is reached, emit the errors if there are any

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants