Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow proc_macro_attribute and macro_rules with the same name #3780

Open
PRO-2684 opened this issue Feb 28, 2025 · 3 comments
Open

Allow proc_macro_attribute and macro_rules with the same name #3780

PRO-2684 opened this issue Feb 28, 2025 · 3 comments
Labels
A-macros Macro related proposals and issues

Comments

@PRO-2684
Copy link

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)

@fmease fmease added A-macros Macro related proposals and issues A-resolve Proposals relating to name resolution. and removed A-resolve Proposals relating to name resolution. labels Feb 28, 2025
@fmease
Copy link
Member

fmease commented Feb 28, 2025

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
Copy link
Member

fmease commented Feb 28, 2025

This proposal likely conflicts with #3697 and #3698.

@PRO-2684
Copy link
Author

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 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Macro related proposals and issues
Projects
None yet
Development

No branches or pull requests

2 participants