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`.
Real output from Deadwood 1.0.1 on a small sample crate. The workspace path is shortened.

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.

CheckWhat Deadwood reportsrustc, CargoClippycargo-machete, cargo-udepscargo-shear
Dead files.rs files no mod or include! reaches from a target rootNever compiled, so never lintedNoNoYes
Unused pub itemspub items nothing live in the workspace reachesdead_code treats a library's pub items as usedNoNoNo
Unused re-exportspub use nothing goes through and outside code can't reachunused_imports treats a library's pub use as usedNoNoNo
Unused dependenciesCargo.toml entries the package's code never namesCargo 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 defaultNoYesYes
Misplaced dependenciesEntries in a table the code naming them can't use, such as a [dependencies] entry only tests useNoNoNoYes, except for #[cfg(test)] code
Test-only pub itemspub items only test code reaches (off by default)NoNoNoNo

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.

Workflow steps
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: rlorenzo/deadwood-rs@65c159dcbf29ed50ee6f784467105f179716a76f # v1.0.1
  with:
    path: .   # workspace to analyze