cargo-expand is a Cargo subcommand that displays the result of Rust macro expansion.
The tool solves the problem of understanding what macros actually generate in your code. When Rust macros expand, the resulting code is normally hidden from view, making it difficult to debug macro behavior or learn what a macro does. cargo-expand runs the Rust compiler in a special mode that performs macro expansion and then pretty-prints the expanded code, showing you the actual generated source alongside your original code.
The tool suits any Rust developer who works with macros and needs visibility into their expansion. This includes debugging unexpected behavior from derive macros, understanding how procedural macros transform your code, or learning how existing macros work. It is particularly valuable when working with complex macro-heavy codebases or when learning macro patterns. The tool integrates directly into the Cargo workflow as a standard subcommand, requiring no special project configuration.
Development on the project shows consistent maintenance with regular updates addressing compiler changes and user-reported issues. The maintainer responds to bug reports and pull requests, keeping the tool compatible with new Rust releases. The codebase remains focused on its core purpose without scope creep, and the tool handles edge cases that arise from Rust's evolving macro system.