mbe: Macro fragment fields by joshtriplett · Pull Request #147025 · rust-lang/rust (original) (raw)
In the course of testing this, I discovered an issue that may require some additional design to solve: matchers like :fn and :adt (and hypothetical future matchers like :struct and :enum) work fine in isolation, but they can't be used as alternatives to each other in a macro, since each one starts out trying to parse an item. A macro that tries to have a ($f:fn) rule and a ($s:adt) rule will not work as expected, because it'll try whichever rule comes first and error on an unexpected item type.
By contrast, proc macros get passed the entire set of tokens, so they can do more sophisticated parsing.
That will require some additional design and thought to come up with a solution for making macro_rules! comparably capable.
(This doesn't prevent presenting this as an unstable-and-incomplete feature, but it's absolutely a blocker for any kind of stabilization.)