cargo-machete is a Cargo tool that detects unused dependencies in Rust
projects, in a fast (yet imprecise) way.
See also the blog post for a detailed writeup.
cargo-machete with cargo:
cargo install cargo-machete
Run cargo-machete in a directory that contains one or more Rust projects (using Cargo for dependency management):
cd my-directory && cargo machete alternatively cargo machete /absolute/path/to/my/directory
cargo machete /absolute/path/to/my/directory
To ignore a certain set of dependencies in a crate, add
Cargo.toml, and specify an
[dependencies] prost = "0.10" # Used in code generated by build.rs output, which cargo-machete cannot check [package.metadata.cargo-machete] ignored = ["prost"]
[package.metadata.cargo-machete] ignored = ["prost"]
If there are too many false positives, consider using the
flag, which will call
cargo metadata --all-features to find final dependency
names, more accurate dependencies per build type, etc. ⚠ This may modify the
Cargo.lock files in your projects.
We welcome community contributions to this project.