The bans check is used to deny (or allow) specific crates, as well as detect and handle multiple versions of the same crate.
cargo deny check bans
Sometimes, certain crates just don't fit in your project, so you have to remove them. However, nothing really stops them from sneaking back in due to innocuous changes like doing a cargo update
and getting it transitively, or even forgetting to set default-features = false, features = ["feature-without-the-thing"]
when the crate is pulled in via the default features of a crate you already depend on, in your entire workspace.
For example, we previously depended on OpenSSL as it is the “default” for many crates that provide TLS. This was extremely annoying as it required us to have OpenSSL development libraries installed on Windows, for both individuals and CI. We moved all of our dependencies to use the much more streamlined native-tls
or ring
crates instead, and now we can make sure that OpenSSL doesn't return from the grave by accident.
The larger your project and number of external dependencies, the likelihood that you will have multiple versions of the same crate rises. This is due to two fundamental aspects of the Rust ecosystem.
This tradeoff of allowing multiple version of the same crate is one of the reasons that cargo is such a pleasant experience for many people new to Rust, but as with all tradeoffs, it does come with costs.
Normally, you will not really notice that you have multiple versions of the same crate unless you constantly watch your build log, but as mentioned above, it does introduce paper cuts into your workflows.
The intention of duplicate detection in cargo-deny is not to “correct” cargo's behavior, but rather to draw your attention to duplicates so that you can make an informed decision about how to handle the situation.