Deadwood
Find the dead code in your Rust workspace that rustc and Clippy miss.
It reads your source without compiling it, so there's no build to wait for and no nightly toolchain. The whole rust-lang/rust workspace takes seconds.
cargo install deadwood-rs
$ deadwood checkDead files:src/csv_export.rs: not reachable from any target of package `ledger` via `mod` declarationsUnused public items:src/lib.rs:10: pub fn `legacy_total` is never referenced by any resolved path in this workspaceUnused dependencies:Cargo.toml: dependency `chrono` is never referenced by any target of package `ledger`Misplaced dependencies:Cargo.toml: dependency `tempfile` is referenced only by the test, example and bench code of package `ledger`, so it belongs in `[dev-dependencies]` rather than `[dependencies]`4 finding(s) in workspace `~/ledger`.
What rustc and Clippy don't report
The dead_code lint assumes a library's pub items are used by someone outside the crate. Inside a workspace that's often false, and that's where dead code piles up.
| Check | What Deadwood reports | rustc, Cargo | Clippy | cargo-machete, cargo-udeps | cargo-shear |
|---|---|---|---|---|---|
| Dead files | .rs files no mod or include! reaches from a target root | Never compiled, so never linted | No | No | Yes |
Unused pub items | pub items nothing live in the workspace reaches | dead_code treats a library's pub items as used | No | No | No |
| Unused re-exports | pub use nothing goes through and outside code can't reach | unused_imports treats a library's pub use as used | No | No | No |
| Unused dependencies | Cargo.toml entries the package's code never names | Cargo 1.100+ warns by default (cargo::unused_dependencies), but only for [dependencies] and only when every target is built; rustc's unused_crate_dependencies is off by default | No | Yes | Yes |
| Misplaced dependencies | Entries in a table the code naming them can't use, such as a [dependencies] entry only tests use | No | No | No | Yes, except for #[cfg(test)] code |
Test-only pub items | pub items only test code reaches (off by default) | No | No | No | No |
Run it in CI
Add the action to a workflow. Pin the full commit SHA of a release tag; the action builds Deadwood from that commit.
On an existing codebase, run deadwood check --write-baseline once and commit the file. After that, only new findings fail the build.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: rlorenzo/deadwood-rs@65c159dcbf29ed50ee6f784467105f179716a76f # v1.0.1 with: path: . # workspace to analyze