Get warning on unused crates in Cargo.toml
It would be great to be able to generate compile warning on unused crate specified in Cargo.toml, similar to #![warn(unused_extern_crates)] but that works with Rust 2018 where one doesn't use extern crate.
This could also be implemented as an external cargo tool that one can run to verify (like clippy), but nicest to have built-in and automatic for everyone
r/rust post about it: https://www.reddit.com/r/rust/comments/cvrglq/emitting_warnings_for_unused_crates_in_cargotoml/
Added the issue links in the top posts here also
We've been using cargo-udeps a bit for this on linux and mac, does work and has been helpful! But does also require nightly Rust, doesn't work on Windows and has a bunch of false positives making it a bit difficult to automate
I'm working on adding a builtin mode to cargo that will hopefully have less false positives than cargo-udeps. cargo-udeps has been built on a bunch of hacks and only had access to what the public cargo api gave it. Cargo instead has access to the full stuff. The mode is already better than cargo-udeps and I want to make it even better:
- https://github.com/rust-lang/cargo/pull/8437
- https://github.com/rust-lang/rust/pull/73945
@est31 that is awesome! looking forward to trying it out on our codebase when it hits nightly
we've for now solved this with https://github.com/bnjbvr/cargo-machete that @bnjbvr built, it does have false positives but ways of working around them so we have this enabled in CI on our bigger projects.
See also https://github.com/est31/cargo-udeps (untested)