Major wildcards in sub-dependencies result in unnecessary duplicate dependencies #13534
Labels
A-dependency-resolution
Area: dependency resolution and the resolver
C-bug
Category: bug
S-triage
Status: This issue is waiting on initial triage.
Problem
When depending on a crate that specifies a major version wildcard (
0.*
or*
), or a major version range (>0.1,<0.10
or>0, <10
) for a dependencyfoo
, if yourroot
crate also has a dependency onfoo
, cargo will resolve duplicate dependencies when there are clear solutions with a single dependency (unless yourroot
is just as loose on the requirement or the major version happens to match the maximum specified in the dependency crate).How this surfaced
This problem has never surfaced before because
crates.io
does not allow crates with major-wildcards to be pushed. Now with the advent of private registries, we have a new wild west with no rules, allowing this problem to present itself.Why would you possibly want to use a major-wildcard??? 🤯
Well, the problem also applies to major-ranges too! It's quite possible for a crate to use only a very limited surface of an API from another crate and want to provide it to the user. A surface so small that you can guarantee that it works across SemVer incompatible versions of a crate.
An example: Say you want to provide a
bevy_ecs
feature on your crate, which simply adds#[derive(Component)]
annotations to some of your structs. You can very easily test and assert that such a feature is compatible withbevy_ecs = ">0.1,<=0.13"
. And while this may be not kosher oncrates.io
, on private registries this can totally be okay.Steps
Here is a failing test that you can plug into
resolver-tests
:The current implementation will return a duplicate
util
:Possible Solution(s)
Proposed fix: #13535
Notes
No response
Version
The text was updated successfully, but these errors were encountered: