Is there a way to see generated code for `derive` attributes?


#1

The available doc does not give much details about the code generated through the derive attribute. In fact the spec only talks about deriving two traits (PartialEq and Clone).

My understanding is that derive is handled in an ad hoc fashion inside the compiler. So yes, a proper specification would be of great help.

My question is more pragmatic. In the mean time do you know of any any way to get the generated code? For example through a flag of rustc.


Now that --pretty=expanded is gone, how do you debug the output of a procedural macro?
#2

I think you can get the expanded output by

rustc <source file> -Z unstable-options --pretty=expanded

#3

Thanks! The code is not so “pretty” with everything expanded but it works really well and does answer my questions about derive.