debugrustCritical
How do I see the expanded macro code that's causing my compile error?
Viewed 0 times
errorhowcompilethemacroseecausingexpandedthatcode
Problem
I have a compile error involving a macro:
Unfortunately, the macro is recursive so it's hard to figure out what the compiler is complaining about, plus it seems like the line numbers are for the expanded macro rather than my code.
How can I see the expanded macro? Is there a flag I can pass to rustc (or even better, cargo) to dump this out?
(This macro is from rust-mdo, though I don't think it matters.)
:6:19: 6:50 error: cannot move out of captured outer variable in an `FnMut` closure
:6 bind ( $ e , move | $ p | mdo ! { $ ( $ t ) * } ) ) ; (
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:1:1: 14:36 note: in expansion of mdo!
:6:27: 6:50 note: expansion site
:1:1: 14:36 note: in expansion of mdo!
:6:27: 6:50 note: expansion site
:1:1: 14:36 note: in expansion of mdo!
src/parser.rs:30:42: 37:11 note: expansion site
error: aborting due to previous errorUnfortunately, the macro is recursive so it's hard to figure out what the compiler is complaining about, plus it seems like the line numbers are for the expanded macro rather than my code.
How can I see the expanded macro? Is there a flag I can pass to rustc (or even better, cargo) to dump this out?
(This macro is from rust-mdo, though I don't think it matters.)
Solution
cargo rustc --profile=check -- -Zunpretty=expanded, but a more concise alternative is the cargo-expand crate. It provides a Cargo subcommand cargo expand which prints the result of macro expansion. It also passes the expanded code through prettyplease which generally results in much more readable code than the default output from rustc.Install by running
cargo install cargo-expand.Context
Stack Overflow Q#28580386, score: 124
Revisions (0)
No revisions yet.