rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

Allow `proc_macro_attribute` and `macro_rules` with the same name

Open PRO-2684 opened this issue 10 months ago • 3 comments

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)

PRO-2684 avatar Feb 28 '25 08:02 PRO-2684

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.

fmease avatar Feb 28 '25 08:02 fmease

This proposal likely conflicts with https://github.com/rust-lang/rfcs/pull/3697 and https://github.com/rust-lang/rfcs/pull/3698.

fmease avatar Feb 28 '25 08:02 fmease

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 .

PRO-2684 avatar Feb 28 '25 09:02 PRO-2684