dtolnay

dtolnay/cargo-expand

Rust Apache-2.0 Dev Tools

Subcommand to show result of macro expansion

3.1k stars
75 forks
recent
GitHub +4 / week

3.1k

Stars

75

Forks

10

Open issues

13

Contributors

1.0.123 16 Jun 2026

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.

Dev Tools Developer Tool Discovery value: 3/10
Documentation 8/10
Activity 9/10
Community 8/10
Code quality 5/10

Inferred from signals mentioned in the README (tests, CI, type safety) — not a review of the actual code.

Overall score 8/10

AI's overall editorial judgment — not an average of the bars above, can weigh other factors too.

rust macro-expansion developer-tool cargo-subcommand code-introspection
Actively maintained Well documented Niche/specialized use case Popular Production ready
Deep Analysis · Based on README and public signals
6d ago

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.

Origin

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.

Growth

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.

In production

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.

Code analysis
Architecture

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.

Tests

Not documented in README. CI pipeline present (GitHub Actions on master branch) but test suite scope and coverage metrics not disclosed.

Maintenance

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.

Honest verdict

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

Risks
  • 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.
Prediction

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.

0 found this helpful

Newsletter

Get analyses like this every Monday

Free weekly digest of the most interesting open-source discoveries.

Languages

Rust
100%

Information

Language
Rust
License
Apache-2.0
Last updated
2w ago
Created
123mo ago
Analyzed with
anthropic/claude-haiku-4-5

Stars over time

Loading…

Contributors over time

Top 100 contributors only — repos with more will plateau at 100.

Loading…

Similar repos

dtolnay

dtolnay/case-studies

A specialized educational repository that dissects tricky Rust code patterns...

2k Rust Education
taiki-e

taiki-e/cargo-llvm-cov

cargo-llvm-cov is a Cargo subcommand that streamlines LLVM source-based code...

1.4k Rust Dev Tools
dtolnay

dtolnay/syn

Syn is a mature parser library for Rust source code, specifically designed for...

3.3k Rust Dev Tools
dtolnay

dtolnay/proc-macro-workshop

An educational workshop teaching Rust procedural macro development through five...

4.8k Rust Education
regexident

regexident/cargo-modules

cargo-modules is a Rust developer tool that visualizes and analyzes a crate's...

1.2k Rust Dev Tools
vs. alternatives
cargo-llvm-cov

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.

cargo-modules

Serves code structure visualization; non-overlapping use case. Lower star count (1246). Both are narrow-purpose Cargo plugins for developers.

rustc -Zunpretty=expanded (native compiler feature)

cargo-expand is explicitly a wrapper around this compiler feature, adding convenience and formatting. Not a competitor but a usability layer over existing infrastructure.

IDE macro expansion features (rust-analyzer, IntelliJ Rust)

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.