Cargo: warn on unused crates?

I appreciate the care rustc expresses in helping me find dead code. In particular, I love this warning:

warning: unused import: `std::io`
 --> src/
3 | use std::io;
  |     ^^^^^^^
  = note: `#[warn(unused_imports)]` on by default

However, more than once now I've cleaned up a bunch of unused imports, verified that tests still pass, and then shipped the code - without noticing that in the process I had removed the last reference to some crate from Cargo.toml. I realize that Rust's linker is smart enough to leave all of that code out, but it still increases build time for clean builds, and it still means keeping up with CVEs, bug reports, and point releases on code that's not actually being used any more.

Is there a way to get Cargo to warn when a library is no longer used in the project it's building?

1 Like

You can use for now. There is being worked on a builtin lint for this:


Amazing to hear it's being worked into Cargo! Thanks for the tool pointer, as well. That's perfect.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.