Expansions made by cargo expand not always 100% faithful
I noticed that, for example, in ref-version.expanded.rs, we see that
impl<'reference, $tgens> From<&'reference $ttype>
... { ... } ...
fn cloned(&self) -> $ttype {
...
${vpat self=Self} => $vtype { $(
appears to expand to
impl<'reference, F> From<&'reference Enum<F>> for EnumReference<'reference, F> {
... { ... } ...
fn cloned(&self) -> Enum<F> {
...
Self::Unit {} => Enum::Unit::<F> {},
Observe that $ttype has apparently expanded to Enum<F> and $vtype to Enum::Unit::<F>. But, actually, derive-adhoc expanded $ttype to Enum::<F> (this can be seen by observing the stderr output). This was evidently removed during one of the various stages of pretty-printing.
I investigated. In particular, I enabled the prettyplease feature of cargo expand, and used the --ugly cargo expand option (in macrotest.rs). I looked at the output of running the build with -Zunpretty-expanded and that seemed to have the problem.
I.e., I think this is a problem with rustc's "pretty printer". I found this issue https://github.com/rust-lang/rust/issues/30924 (that doesn't seem to precisely cover this situation, but it's at least adjacent).
I'm not sure it will be easy to do better here than to just document the issue. Producing a faithful expanded output with sensible formatting would be quite hard. It might even involve using a completely different approach to both capturing the expanded output and pretty-formatting it.