Skip to content
Latchkey

cargo tree -i: Trace Why a Crate Is Pulled In

cargo tree -i <crate> shows the reverse dependency tree: which of your packages cause a given crate (and version) to be included.

When a single crate appears twice at different versions, builds bloat and features unify oddly. cargo tree -i and -d tell you exactly who is responsible.

What it does

cargo tree prints the dependency graph. -i <pkg> inverts it to show paths from your crates down to that package. -d lists only crates that appear in more than one version. -e features annotates which features each edge enables.

Common usage

Terminal
cargo tree -i syn                 # who depends on syn
cargo tree -d                     # duplicate versions
cargo tree -e features -i serde   # feature edges to serde
cargo tree --target x86_64-unknown-linux-gnu

Flags

FlagWhat it does
-i, --invert <pkg>Show what depends on the package (reverse tree)
-d, --duplicatesShow only crates with multiple versions
-e, --edges <kinds>Edge kinds to show: normal, build, dev, features
--target <triple>Resolve for a specific target
--prefix depthPrint depth numbers instead of tree lines

In CI

Run cargo tree -d in a step that fails on unexpected duplicate versions to keep build times and binary size in check. It reads Cargo.lock, so it is fast and needs no compilation; cache ~/.cargo/registry so the index is available offline.

Common errors in CI

"error: package X not found" from -i means the crate name is misspelled or is not in the resolved graph for the chosen target. "error: the lock file ... needs to be updated" appears with --locked if Cargo.lock is stale. Empty output from -d simply means there are no duplicate versions, which is the desired state.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →