How to expand all the macros in a project?

I am browsing a Rust codebase containing many macros and their invocations, and I'd like to see them in expanded mode most of the time, because I find it easier to look at the generated code rather than work through the macro each time.

IntelliJ has a "Show macro expansion" option in its Right Click menu, but it just shows the generated code in a temporary popup window.

Is there a macro-expand phase within cargo that gives me access to generated code, similar to the generate-sources phase of Maven?

There is the cargo-expand tool.


Thanks. Able to make use of that. It seems to dump all the macro expansions into one file, and currently Jetbrains can't blend this seamlessly with the existing code base, but better than nothing!

Well, I think it's more targeted/intended for interactive use at the command prompt. Including pretty printing and even coloring/syntax highlighting the results. You can also make it expand only certain functions or modules (as explained e. g. in the GitHub README).