duplicate definition error depends on macro declaration order
efd80b3
Opened by Alex Burka at
Consider this code:
macro_rules! m { () => { mod Foo {} } }
struct Foo {}
m!();
The error is, "a module named Foo has already been defined in this module", pointing at line 2, the struct definition. Note that from, I would say, a user's perspective, the module is actually declared after the struct (by calling the macro).
Furthermore, switching lines 1 and 2 (not lines 2 and 3) switches the blame to the mod as being a duplicate.
error[E0428]: the name `Foo` is defined multiple times --> src/lib.rs:2:1 | 1 | macro_rules! m { () => { mod Foo {} } } | ------- previous definition of the module `Foo` here 2 | struct Foo {} | ^^^^^^^^^^ `Foo` redefined here | = note: `Foo` must be defined only once in the type namespace of this moduleEsteban Kuber at 2023-07-28 12:53:36