Skip to content

Using Macros 2.0 to generate a module does not allow access to items #47797

Closed
@alexreg

Description

@alexreg

I see no reason why the following code shouldn't work on the latest nightly,

#![feature(decl_macro)]

macro foo($mod_name:ident) {
    pub mod $mod_name {
        pub const BAR: u32 = 1;
    }
}

foo!(foo_mod);

fn main() {
	println!("{}", foo_mod::BAR);
}

yet I get an odd error.

error[E0425]: cannot find value `BAR` in module `FooMod`
  --> src/main.rs:12:25
   |
12 |     println!("{}", FooMod::BAR);
   |                            ^^^ not found in `FooMod`
help: possible candidate is found in another module, you can import it into scope
   |
3  | use FooMod::BAR;
   |

error: aborting due to previous error

Perhaps I'm missing something about how hygiene works in macros 2.0?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions