mozilla / fxrecord

https://mozilla.github.io/fxrecord
Mozilla Public License 2.0
3 stars 3 forks source link

Rewrite `impl_message!` as a proc macro #16

Closed brennie closed 4 years ago

brennie commented 4 years ago

The new message implementation macro, message_ty!, is written as a procedural macro to make the maintenance burden easier. Declarative macros may be conceptually simpler, but attempting to make impl_message! work for either struct or enum members was hard and got very messy very fast.

Additionally rust#22694 prevents using declarative macros to generate item fragments (e.g., enum variants inside enum Foo {}), which makes creating a maintainable decl macro quite hard.

It ended up being less effort to both rewrite it as a proc macro and also add support for enum members. As a side effect, this macro provides better error spans when it is provided with invalid input (instead of the generic no rules expected the token {token} error).