I have created a runnable sample repo that contains the following module:
// double export of a symbol occurs here
pub use funny_derive::Funny;
mod funny;
pub use self::funny::Funny;
Despite having two symbols that contain the exact same name, it does not appear to have any compilation errors or name conflicts. Is this a bug in the Rust compiler?
Having said that, I know built in macros like Debug also match their trait name. Perhaps this is just some kind of expected special behavior with derive macros. Either way, I'd be curious to hear from someone more knowledgeable about the compiler.
This behavior is expected, because you can't use a macro where a type/trait/value is expected, and you can't use a type/trait/value where a macro is expected. So it isn't possible for them to conflict even if they have the same name.
This is intentionally supported. Rust syntax is such that there couldn't be an ambiguity between a macro called Funny and a type called Funny in any position in the grammar.
There is a third namespace as well for values, which is also not ambiguous with either of the previous two. For example the following program compiles with a name X present in all three namespaces.
// X in the macro namespace
macro_rules! X {
() => {};
}
// X in the type namespace (types, traits, modules)
struct X {}
// X in the value namespace (constants, statics, functions, enum variants)
const X: () = ();
fn main() {
// unambiguously the macro X
X!();
// unambiguously the type X
let _: X;
// unambiguously the value X
let _ = X;
}
Unit structs ( struct S; ) and tuple structs ( struct S(A, B); ) are both types and values. The value corresponding to a unit struct is like a constant whose value is that unit struct, and the value corresponding to a tuple struct is like a function that takes the tuple elements and returns the tuple struct. Constants and functions are both values.
Braced structs ( struct S { a: A } ) are types only.