Skip to content

cargo add: Be clever and infer version from Cargo.lock #41

@killercup

Description

@killercup

Like @gankro and @filsmick described on Reddit, cargo add could learn to add dependencies with versions that are already used by another dependency.

Let's say I have my-http-thingy = "0.4.2" already in my Cargo.toml. Now, we run cargo add my-url-parser. Instead of fetching the latest version (e.g., 6.6.6), we should first suggest to use 1.3.37 which my-http-thingy already depends on (and which is incompatible to the latest version).

I'm not sure if we should do this in every case. If part of my dependency tree looks like a (0.2.1) → b (0.4.2) → c (0.6.0) → d (1.2.0) and I want to cargo add d, is the version c depends on still relevant? How should we tell this to a user?

Should we give the user a choice or should we only do this when a special argument is given (e.g., --infer-versions, or --keep-dependencies-flat)? (Personally, I thing interactivity is okay for cargo add, even though it might make the code more complex and we should offer an op-out).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions