Feature Request: Add support for cargo-machete
Is your feature request related to a problem? Please describe. Yes, it's complicated to detect unused dependencies.
Describe the solution you'd like Would you be open to adding an integration with cargo machete to highlight unused dependencies in toml files?
Detected unused dependency would be highlighted with potential actions to solve (remove dep, add cargo-machete metadata)
Describe alternatives you've considered
- Using udeps (see FAQ)
- Using a make target (less ergonomics)
- Making another extension (see FAQ)
Downsides:
-
cargo macheteis faillible and has known false positive that can't and won't be fixed. (EG dependencies only used in macros) => I think upside of compilation time of not compiling unused deps is worth it. - It might slow down the execution of the extension => I think upside of compilation time of not compiling unused deps is worth it.
- I don't think
cratescurrently triggers when modifying*.rsfiles which might become a requirement because a dependency usage can change while modifying code.
FAQ:
- Why
cargo macheteand notcargo udeps? Speed :rocket: udeps requires compiling the crate which takes some time and can become cubersome when saving cargo.toml files. - Why integrate it within
cratesand not a custom extension? Unused dependencies is very small problem and I'm not sure it would be worth the investment to create a extension just for that. - Activate it by default or not? I think it should be activated by default as developers might not be aware that rustc doesn't warn on unused dependencies (specially since it does so much other things)
rustc doesn't warn on unused dependencies
I agree it's surprising but they later added a lint you can enable in your Cargo.toml.
Pro
- machete is only approximate and can be wrong
- a lint warns you wherever/however you build
Neg
- Bit of a pest to add to all your Cargo.tomls
- I think it might be incorrect on benchmark dependencies (tbc)
[lints.rust]
unused_crate_dependencies = "warn"
or for workspaces:
[workspace.lints.rust]
unused_crate_dependencies = "warn"
which you can inherit in members
[lints]
workspace = true
Oh and I see it's been implemented in a fork. Not tried it:
https://marketplace.visualstudio.com/items?itemName=citreae535.sparse-crates