Should `Cargo.lock` be listing these disabled dependencies?
â Rust đ 2026-01-10 đ¤ surdeus đī¸ 2In a brand new, 2024-edition Cargo project, add version 0.9.0 of mitsein as a dependency. mitsein has arrayvec listed as an optional dependency, and there is an explicit "arrayvec" feature (disabled by default) that uses it. As you'd expect, because the "arrayvec" feature is not enabled, arrayvec is not listed in Cargo.lock, and it is not listed under the "resolve" key in cargo metadata's output. However, if you then enable the "serde" feature of mitsein, which declares a dependency on "arrayvec?/serde" [1], then arrayvec will appear in Cargo.lock and in the "resolve" section of cargo metadata even though it's still not actually used by anything (and cargo tree -i arrayvec even fails to find it).
Is this intentional behavior on Cargo's part? I couldn't find any related issues on GitHub. If this is intentional, is there a simple or straightforward way to filter arrayvec and other similarly unused dependencies out of cargo metadata?
Meaning "only enable the given feature [
serde] if something else enables the optional dependency [arrayvec]" âŠī¸
2 posts - 2 participants
đˇī¸ Rust_feed