I'm trying to debug a function-like proc-macro, and I'm getting "error[E0782]: expected a type, found a trait" inside the macro expansion. How can I see where in the expanded macro this is happening?
Running cargo expand just dumps out everything (which, in my case, is a lot), but since the original error message contains no clue as to where in that giant pile of code the compiler expected a type instead of a trait, I don't know where to look.
I also tried RUSTFLAGS="-Zmacro-backtrace" cargo +nightly check as recommended by the error message, but that yields the same output as the original cargo check command.
A quick-and-dirty approach that often works well is to copy/paste the generated code and compile it. Often, just copying it triggers the IDE's code awareness. (EDIT: @SkiFire13 beat me to it )
Using rust-analyzer, you can select a single macro call and run “Inline macro” to replace the macro call with its expansion. This way, you get code that in most cases, will produce the same error when compiled because it’s in the same context. (Not all cases will work because macro hygiene can produce outcomes that cannot be expressed in plain code.)