Macros 2.0 - weird error

Take the following program:

#![feature(decl_macro)]

mod c {
    pub mod a {
        pub mod b {
            pub macro foo() {
                super::super::Foo
            }
            
            fn foo() {
                super::super::Foo;
            }
        }
    }
    
    struct Foo;
}

fn main() {
    c::a::b::foo!();
}

It errors for the macro, but not for the function (Rust Playground):

error[E0425]: cannot find value `Foo` in module `super::super`
  --> src/main.rs:7:31
   |
7  |                 super::super::Foo
   |                               ^^^ help: a function with a similar name exists (notice the capitalization): `foo`
...
10 |             fn foo() {
   |             -------- similarly named function `foo` defined here
...
20 |     c::a::b::foo!();
   |     --------------- in this macro invocation
   |
note: unit struct `crate::c::Foo` exists but is inaccessible
  --> src/main.rs:16:5
   |
16 |     struct Foo;
   |     ^^^^^^^^^^^ not accessible
   = note: this error originates in the macro `c::a::b::foo` (in Nightly builds, run with -Z macro-backtrace for more info)

Can somebody explain this? I thought macros 2.0 invocation is supposed to behave "as if" it was written in the macro's module.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.