🦀
Rust で 未使用の dependencies を探す
これって使ってたんだっけ?消していいんだっけ?となったときの解決法
使うもの
https://github.com/est31/cargo-udeps
!
Some unused crates might not be detected. This includes crates used by std and its dependencies as well as crates that are already being used by dependencies of the studied crate.
ref: https://github.com/est31/cargo-udeps#cargo-udeps
ということで、不要な dependencies は消せるけど、行数を最小限にしたい、とかのユースケースには向いてなさそう(現時点では)
Bug としてあげられてるので、今後対応が入るのかもしれない
手順
!
README があるのでそれが一番正確
ref: https://github.com/est31/cargo-udeps#cargo-udeps
インストール
cargo install cargo-udeps --locked
# nightly がいるらしいので入れる
rustup install nightly
実行
cargo +nightly udeps
Checking rpassword v5.0.1
Checking repng v0.2.2
Checking app v0.1.0 (/workspace)
Finished dev [unoptimized + debuginfo] target(s) in 1.88s
info: Loading save analysis from "/workspace/target/debug/deps/save-analysis/app-0c8c08d5e5865373.json"
unused dependencies:
`app v0.1.0 (/workspace)`
└─── dependencies
├─── "repng"
├─── "rpassword"
├─── "sha2"
└─── "whoami"
Note: These dependencies might be used by other targets.
To find dependencies that are not used by any target, enable `--all-targets`.
Note: They might be false-positive.
For example, `cargo-udeps` cannot detect usage of crates that are only used in doc-tests.
To ignore some dependencies, write `package.metadata.cargo-udeps.ignore` in Cargo.toml.
今回は、これらが不要なものとして検出された。
├─── "repng"
├─── "rpassword"
├─── "sha2"
└─── "whoami"
Discussion