Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC for allowing macros in all ident positions #215
Conversation
This comment has been minimized.
This comment has been minimized.
SiegeLord
commented
Aug 28, 2014
|
I don't think blindly allowing macros everywhere is a good idea. For example, it might be cool to have syntax such as |
This comment has been minimized.
This comment has been minimized.
|
@SiegeLord This isn't about blindly allowing them everywhere; it's about allowing them where we alow idents. But yes, this would break that sort of syntax. I personally don't see many uses for that syntax though -- and besides we can always write |
This comment has been minimized.
This comment has been minimized.
SiegeLord
commented
Aug 28, 2014
|
I don't mind making macro writer write ugly code in exchange for the macro user being able to write beautiful code. It is irrelevant that you can write A use case for that syntax involves multi-dimensional slices for matrices ( |
This comment has been minimized.
This comment has been minimized.
|
The only workaround I know of is a syntext that's ugly to use |
This comment has been minimized.
This comment has been minimized.
|
@Manishearth thank you for the RFC. Right now we are not adding major new features to macros for fear that Rust metaprogramming is becoming a huge, unspeccable mess. Closing. |
Manishearth commentedAug 28, 2014
Summary
Macros which resolve to idents should be usable in all positions that expect idents, including function/struct/enum names in definitions, et cetera.
Currently they can only be used as variable names.
Motivation
This will allow for creating better macros which resolve to functions. For example:
can be created to generate setters just by calling
make_setter(foo)(which will createset_foo())Currently, using macros in this manner will lead to errors like
See also: rust-lang/rust#13294
Detailed design
This will probably require converting
ast::Identto an enum allowing for aNamedIdentvsMacroIdentduality.Drawbacks
None that I see
Alternatives
Suggestions welcome
Unresolved questions
I'm rather unsure about the implementation.