Skip to content

Commit

Permalink
fix(resolver): Include dep spec in rejected versions error
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Dec 11, 2024
1 parent b38e7c2 commit 1c07adc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
12 changes: 10 additions & 2 deletions src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,18 @@ pub(super) fn activation_error(
Ok(c) => c,
Err(e) => return to_resolve_err(e),
};

let locked_version = dep
.version_req()
.locked_version()
.map(|v| format!(" (locked to {})", v))
.unwrap_or_default();
let _ = writeln!(
&mut msg,
"no matching versions for `{}` found",
dep.package_name()
"failed to select a version for the requirement `{} = \"{}\"`{}",
dep.package_name(),
dep.version_req(),
locked_version
);
for candidate in version_candidates {
match candidate {
Expand Down
16 changes: 8 additions & 8 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ fn relying_on_a_yank_is_bad_http() {
let _server = setup_http();
relying_on_a_yank_is_bad(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching versions for `baz` found
[ERROR] failed to select a version for the requirement `baz = "=0.0.2"`
version 0.0.2 is yanked
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `bar v0.0.1`
Expand All @@ -875,7 +875,7 @@ required by package `bar v0.0.1`
fn relying_on_a_yank_is_bad_git() {
relying_on_a_yank_is_bad(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching versions for `baz` found
[ERROR] failed to select a version for the requirement `baz = "=0.0.2"`
version 0.0.2 is yanked
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `bar v0.0.1`
Expand Down Expand Up @@ -922,7 +922,7 @@ fn yanks_in_lockfiles_are_ok_http() {
"#]],
str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching versions for `bar` found
[ERROR] failed to select a version for the requirement `bar = "*"`
version 0.0.1 is yanked
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`
Expand All @@ -940,7 +940,7 @@ fn yanks_in_lockfiles_are_ok_git() {
"#]],
str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching versions for `bar` found
[ERROR] failed to select a version for the requirement `bar = "*"`
version 0.0.1 is yanked
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`
Expand Down Expand Up @@ -993,7 +993,7 @@ fn yanks_in_lockfiles_are_ok_for_other_update_http() {
"#]],
str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching versions for `bar` found
[ERROR] failed to select a version for the requirement `bar = "*"`
version 0.0.1 is yanked
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`
Expand All @@ -1017,7 +1017,7 @@ fn yanks_in_lockfiles_are_ok_for_other_update_git() {
"#]],
str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching versions for `bar` found
[ERROR] failed to select a version for the requirement `bar = "*"`
version 0.0.1 is yanked
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`
Expand Down Expand Up @@ -3228,7 +3228,7 @@ fn unknown_index_version_error() {
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching versions for `bar` found
[ERROR] failed to select a version for the requirement `bar = "^1.0"`
version 1.0.1 requires a Cargo version that supports index version 4294967295
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.1.0 ([ROOT]/foo)`
Expand Down Expand Up @@ -3266,7 +3266,7 @@ fn unknown_index_version_with_msrv_error() {
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching versions for `bar` found
[ERROR] failed to select a version for the requirement `bar = "^1.0"`
version 1.0.1 requires cargo 1.2345
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.1.0 ([ROOT]/foo)`
Expand Down

0 comments on commit 1c07adc

Please sign in to comment.