cargo update -p $some_dependency
causes unexpected dependency downgrades
#14456
Labels
cargo update -p $some_dependency
causes unexpected dependency downgrades
#14456
Problem
When I run
cargo update -p $SOME_DEPENDENCY
I sometimes notice unexpected changes inCargo.lock
for unexpected packages, specifically some crates depend on a lower major version than before.I've been puzzled by this for a while, but today it struck again and I was able to reproduce the behavior.
A short description of the problem:
aaa 0.1.0
andaaa 0.2.0
), andbbb
in the dependency tree is compatible with multiple major versions (aaa = { version = ">=0.1, <=0.2" }
),cargo update -p ccc
on an unrelated dependency can causebbb
to switch from usingaaa 0.2.0
toaaa 0.1.0
inCargo.lock
.My naive expectation is that
cargo update -p
should not modify unrelated dependency edges unnecessarily. Downgrading across a major version is particularly unwelcome (even when the dependent appears to permit it). The resultingCargo.lock
should only contain changes that are forced by the package that was updated.Steps
Here is one way to reproduce the issue with some common dependencies:
Cargo.lock
with some versions from the past:cargo check
to create aCargo.lock
with those dependency versions.We now have a transitive dependency on
heck 0.5.0
.Add another direct dependency on
clap_derive
:cargo check
to updateCargo.lock
.Note we are now (indirectly) depending on
heck 0.4.0
andheck 0.5.0
.Remove the version pinning:
If you want you can run
cargo check
again, but it won't changeCargo.lock
since all dependencies are satisfied.cargo tree
and observe thatprost-build
is usingheck 0.5.0
:or look at
Cargo.lock
:Run
cargo update -p diesel
. (Because of a new rustsec vulnerability.)Observe that
Cargo.lock
has changed in unexpected ways:Further observe that if I manually revert this change from
Cargo.lock
, the dependency tree is stable, i.e. runningcargo check
will not force it to be downgraded again.If I go back to the state before I ran
cargo update
and instead modifyCargo.toml
to saydiesel = "2.2.3"
and runcargo check
then I do not see the unrelated change inCargo.lock
. From this I conclude that this was an unnecessary/unforced change toCargo.lock
that seems to be specific tocargo update
.Possible Solution(s)
No idea.
Notes
I work in a very large Cargo workspace with thousands of dependencies, and updating all workspace dependencies at once is too disruptive. We perform minimal dependency updates when rustsec advisories appear.
Version
The text was updated successfully, but these errors were encountered: