Subcommand to show result of macro expansion
3.1k
Stars
75
Forks
10
Open issues
13
Contributors
AI Analysis
cargo-expand is a Rust developer tool that displays the result of macro expansion and derive macro code generation for the current crate, making it easier to understand what the compiler actually sees. It wraps compiler internals (cargo rustc with -Zunpretty=expanded) and optionally formats output with rustfmt for readability. This tool is specialized for Rust macro developers and anyone debugging macro behavior—not useful outside the Rust ecosystem.
Inferred from signals mentioned in the README (tests, CI, type safety) — not a review of the actual code.
AI's overall editorial judgment — not an average of the bars above, can weigh other factors too.
Rust macro expansion debugger with steady adoption among compiler and library developers
cargo-expand is a Cargo subcommand that displays the result of Rust macro and derive macro expansion, wrapped around the compiler's -Zunpretty=expanded flag. It serves Rust developers who need to inspect what code their macros generate—essential for macro authors, library maintainers debugging proc-macros, and developers learning how derives work. Adoption appears concentrated among the Rust macro ecosystem community and library maintainers rather than general application developers.
Created in 2016 by David Tolnay, a prominent Rust ecosystem contributor, cargo-expand emerged to make the compiler's verbose macro expansion output more accessible. It has remained relatively focused on its core mission: providing a readable, formatted view of expanded code via optional rustfmt integration.
The project gained approximately 3,100 stars over 10 years with modest recent velocity (3 stars in 7 days as of 2026-06-24). Growth appears organic and steady rather than volatile, reflecting its position as a specialized but essential tool within the macro-focused Rust ecosystem. Activity is concentrated among library authors and macro developers rather than trending toward mainstream adoption.
Adoption not verified through explicit production case studies or usage surveys in README. However, implicit evidence: (1) maintained by dtolnay, a highly visible Rust ecosystem figure whose projects see wide indirect adoption, (2) presence on crates.io with installation instructions, (3) consistent CI maintenance and recent activity, (4) ecosystem visibility within macro-focused Rust communities. Real-world usage likely exists among proc-macro developers and library maintainers, but quantitative adoption metrics not publicly available.
Appears to be a thin wrapper around Cargo and rustc internals, using the compiler's expansion API and optionally piping output through rustfmt. Likely maintains compatibility with evolving Rust toolchain versions. README does not detail internal architecture or dependency graph.
Not documented in README. CI pipeline present (GitHub Actions on master branch) but test suite scope and coverage metrics not disclosed.
Last push 2026-06-24 (10 days ago relative to current date 2026-07-04) indicates active maintenance. Project has been continuously maintained across a 10-year lifespan. No evidence of stagnation; appears to receive updates in response to Rust toolchain changes and user needs. Slow growth velocity is consistent with a mature, specialized tool rather than indicating abandonment.
ADOPT IF: you are a Rust macro author, proc-macro library maintainer, or need to inspect derive expansion behavior during development or debugging. AVOID IF: you are building end-user Rust applications that do not directly author macros—this is not a general-purpose tool. MONITOR IF: you are evaluating Rust tooling ecosystem maturity; cargo-expand's longevity and consistent maintenance signal healthy macro-focused developer infrastructure.
Independent dimensions
Mainstream potential
3/10
Technical importance
7/10
Adoption evidence
4/10
- Dependency on unstable rustc APIs (-Zunpretty=expanded); changes to compiler internals could break expansion output format or functionality, though maintainer has track record of responsive updates.
- Output is explicitly lossy (README includes macro hygiene caveats); expanded code is a visualization aid, not a guarantee of semantic equivalence. Users may misinterpret results.
- Adoption appears concentrated in library/macro ecosystem; may see reduced relevance if Rust IDE tools mature and subsume macro expansion introspection into IDEs, though CLI tool likely persists.
- Slow growth and modest star count may signal low discoverability or low need outside specialized use cases, rather than indicating quality issues.
- Limited public documentation of real-world adoption; cannot quantify how many projects actively depend on this tool in production workflows.
cargo-expand will likely remain a stable, actively maintained niche tool for the Rust macro and library ecosystem. Gradual adoption of IDE-integrated macro expansion may reduce CLI tool usage for interactive exploration, but cargo-expand will probably persist as a scriptable, toolchain-independent option. Growth is unlikely to accelerate significantly unless macro-heavy Rust development becomes mainstream.
Newsletter
Get analyses like this every Monday
Free weekly digest of the most interesting open-source discoveries.
Languages
Information
- Language
- Rust
- License
- Apache-2.0
- Last updated
- 2w ago
- Created
- 123mo ago
- Analyzed with
- anthropic/claude-haiku-4-5
Stars over time
Contributors over time
Top 100 contributors only — repos with more will plateau at 100.
Open issues
Exit code is 0 even when expansion errors occur
Expand functions impl-ed on structs.
Correct way of expanding once and get code for each file separately
Output is unreadable if the terminal uses black text on white background
Expand doctests
Open pull requests
No open pull requests.
Similar repos
dtolnay/case-studies
A specialized educational repository that dissects tricky Rust code patterns...
taiki-e/cargo-llvm-cov
cargo-llvm-cov is a Cargo subcommand that streamlines LLVM source-based code...
dtolnay/proc-macro-workshop
An educational workshop teaching Rust procedural macro development through five...
| Repository | Stars | Week Δ | Language | Score | Updated |
|---|---|---|---|---|---|
|
|
3.1k | +4 | Rust | 8/10 | 2w ago |
|
|
2k | — | Rust | 8/10 | 2w ago |
|
|
1.4k | — | Rust | 8/10 | 6d ago |
|
|
3.3k | — | Rust | 9/10 | 1d ago |
|
|
4.8k | — | Rust | 9/10 | 3w ago |
|
|
1.2k | — | Rust | 8/10 | 19h ago |
Different problem domain (code coverage vs. macro expansion). Both are specialized Cargo subcommands; cargo-llvm-cov has higher star count (1413 vs. 3100 for expand) but serves coverage analysis, not macro introspection.
Serves code structure visualization; non-overlapping use case. Lower star count (1246). Both are narrow-purpose Cargo plugins for developers.
cargo-expand is explicitly a wrapper around this compiler feature, adding convenience and formatting. Not a competitor but a usability layer over existing infrastructure.
IDEs increasingly expose macro expansion inline; cargo-expand remains more explicit and CLI-native. Complementary rather than directly competing; IDEs may reduce use cases for CLI expansion but unlikely to eliminate them entirely.

