rust-ecosystem icon indicating copy to clipboard operation
rust-ecosystem copied to clipboard

Get warning on unused crates in Cargo.toml

Open repi opened this issue 6 years ago • 6 comments

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

repi avatar Apr 01 '19 21:04 repi

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

repi avatar Aug 27 '19 08:08 repi

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

repi avatar Jul 04 '20 22:07 repi

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 avatar Jul 04 '20 22:07 est31

@est31 that is awesome! looking forward to trying it out on our codebase when it hits nightly

repi avatar Jul 05 '20 09:07 repi

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.

repi avatar Nov 13 '22 13:11 repi

See also https://github.com/est31/cargo-udeps (untested)

nielsle avatar Nov 13 '22 16:11 nielsle