Allow `proc_macro_attribute` and `macro_rules` with the same name
We already allow derive macros and traits to share the same name, so that library users only need to use once:
use my_crate::MyTrait;
#[derive(MyTrait)]
struct MyStruct {
// ...
}
fn main() {
// ...
}
So we should also allow proc_macro_attribute and macro_rules with the same name, like:
use my_macro::my_macro;
#[my_macro]
struct MyStruct {
// ...
}
fn main() {
my_macro!(MyStruct);
}
Related: https://internals.rust-lang.org/t/allow-attribute-and-function-macros-to-share-name/19510 (closed)
Well, derive macros and traits can currently live side by side because Rust features a (relatively rigid) namespace system consisting of Value, Type (includes traits) and Macro.
This proposal likely conflicts with https://github.com/rust-lang/rfcs/pull/3697 and https://github.com/rust-lang/rfcs/pull/3698.
Well, derive macros and traits can currently live side by side because Rust features a (relatively rigid) namespace system consisting of Value, Type (includes traits) and Macro.
Maybe we could further divide Macro into Derive, Attribute and Functional Macro. Macros by example and procedural macros are simply two ways of defining macros, and can both produce any kind of macro mentioned above. This architecture could also possibly solve #3697 and #3698 .