9

I just found How do I see the expanded macro code that's causing my compile error?. Is it possible to get the expansion of a single macro instead of the whole file?

Peter Hall
  • 53,120
  • 14
  • 139
  • 204
bertfred
  • 412
  • 4
  • 9

2 Answers2

17

The cargo-expand command is really just a thin wrapper around cargo rustc -- -Zunstable-options --pretty=expanded, which is itself a blunt instrument. You can't target a specific macro.

However, since version 0.4, you can reduce some noise by specifying an extra path argument to expand only macros used by that module:

$ cargo expand path::to::module
Peter Hall
  • 53,120
  • 14
  • 139
  • 204
6

"Show expanded macro" and "Show recursively expanded macro" commands were recently added to IntelliJ Rust.

A gif demo from CLion blog post:

Demo

ozkriff
  • 1,269
  • 15
  • 23