cargo add version should default to requirement already present in workspace #15195
Labels
C-enhancement
Category: enhancement
Command-add
S-triage
Status: This issue is waiting on initial triage.
Problem
When using
cargo add
, the version chosen for the new dependency appears to always be the latest one from crates.io, even if another package the workspace already has that package at a different version.Steps
Steps
Then
Expected results
Actual results
Possible Solution(s)
Look through the workspace and pick a version (more precisely, a "requirement") already used elsewhere, by default. The precise algorithm needs a little thought, but it should probably prefer later versions (requirements that would select later versions).
Notes
I'm filing this as a bug because in a medium to large workspace the default behaviour easily results in duplicated crates. Feel free to downgrade this ticket if you feel like it.
Also, I'm not sure what compatibility guarantees
cargo add
offers. It's possible that any new/changed behaviour would have to be conditional somehow.(Also, I wonder if the version selection is MSRV-aware?)
Version
(edited to normalise ordering in example Cargo.toml's.)
The text was updated successfully, but these errors were encountered: