How do I see the expanded macro code that’s causing my compile error?

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 rustfmt which generally results in much more readable code than the default output from rustc.

Install by running cargo install cargo-expand.

Leave a Comment