Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple pre-release versions of a crate to co-exist #6019

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,10 @@ impl RemainingCandidates {
// Versions `a` and `b` are compatible if their left-most nonzero digit is the
// same.
fn compatible(a: &semver::Version, b: &semver::Version) -> bool {
if !a.pre.is_empty() || !b.pre.is_empty() {
return a == b;
}

if a.major != b.major {
return false;
}
Expand Down
35 changes: 34 additions & 1 deletion tests/testsuite/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ fn resolving_backtrack_features() {
}

#[test]
fn resolving_allows_multiple_compatible_versions() {
fn resolving_allows_multiple_incompatible_versions() {
let reg = registry(vec![
pkg!(("foo", "1.0.0")),
pkg!(("foo", "2.0.0")),
Expand Down Expand Up @@ -541,6 +541,39 @@ fn resolving_allows_multiple_compatible_versions() {
);
}

#[test]
fn resolving_allows_multiple_prerelease_versions() {
let reg = registry(vec![
pkg!(("foo", "1.0.0")),
pkg!(("foo", "2.0.0")),
pkg!(("foo", "2.0.0-alpha")),
pkg!(("foo", "2.0.0-beta")),
pkg!("bar" => ["d1", "d2", "d3", "d4"]),
pkg!("d1" => [dep_req("foo", "=1")]),
pkg!("d2" => [dep_req("foo", "=2")]),
pkg!("d3" => [dep_req("foo", "=2.0.0-alpha")]),
pkg!("d4" => [dep_req("foo", "=2.0.0-beta")]),
]);

let res = resolve(&pkg_id("root"), vec![dep("bar")], &reg).unwrap();

assert_contains(
&res,
&names(&[
("root", "1.0.0"),
("foo", "1.0.0"),
("foo", "2.0.0"),
("foo", "2.0.0-alpha"),
("foo", "2.0.0-beta"),
("d1", "1.0.0"),
("d2", "1.0.0"),
("d3", "1.0.0"),
("d4", "1.0.0"),
("bar", "1.0.0"),
]),
);
}

#[test]
fn resolving_with_deep_backtracking() {
let reg = registry(vec![
Expand Down