Should we design a new simple macro system?

in community libraries, macro nearly lives everywhere.

yes, it uses more smoothly, but when you try to figure it out what happens or how to deeply use , you will have to face a situation that you have to learn a minimal lang designed by this lib using macro.

if only one lib ,it will be fine, but most of them? every lib has its own taste...really ....

macro everywhere is really one of the reason will lead rust to what happens in c++

hope rust become better

Even if you would like to redesign it, the current macro system is out there and won't go away because of stability.

You can design macros nice or ugly, just as you can design an API nice or unusable. Ideally the lib doesn't expose a DSL for each macro.

What definitly should be done however is: a) Allow users to easier inspect macro output. (Currently we only have cargo expand for this.) b) Better error handling in macros c) Better IDE support.

The good thing is that, for all of this there are ideas out there

1 Like

Macros in rust can't produce arbitrary tokens like in C++. They have to produce a valid item, expression or pattern. In addition macros can only be used in these positions. Furthermore in rust macros can accept actual rust syntax, while in C++ they are left with a bunch of tokens that is not really parseable by the macro. Combined this makes Rust macros significantly less messy than C++ macros.

IntelliJ IDEA’s inline macro expansion support is getting really good.


Rust-analyzer also supports macro expansion. It shows it in a separate editor view though.