Skip to content

Commit

Permalink
fix error message trying patch non-existing package with prerelease v…
Browse files Browse the repository at this point in the history
…ersion
  • Loading branch information
loloicci authored and Eh2406 committed Sep 12, 2023
1 parent c29c25b commit 7880215
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ impl Dependency {
self
}

/// Sets the version requirement as any for this dependency.
pub fn set_version_req_as_any(&mut self) -> &mut Dependency {
Rc::make_mut(&mut self.inner).req = OptVersionReq::Any;
self
}

pub fn set_platform(&mut self, platform: Option<Platform>) -> &mut Dependency {
Rc::make_mut(&mut self.inner).platform = platform;
self
Expand Down
3 changes: 1 addition & 2 deletions src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,8 @@ pub(super) fn activation_error(
// Maybe the user mistyped the ver_req? Like `dep="2"` when `dep="0.2"`
// was meant. So we re-query the registry with `dep="*"` so we can
// list a few versions that were actually found.
let all_req = semver::VersionReq::parse("*").unwrap();
let mut new_dep = dep.clone();
new_dep.set_version_req(all_req);
new_dep.set_version_req_as_any();

let mut candidates = loop {
match registry.query_vec(&new_dep, QueryKind::Exact) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2691,7 +2691,7 @@ fn mismatched_version_with_prerelease() {
.with_stderr(
r#"[UPDATING] `dummy-registry` index
[ERROR] failed to select a version for the requirement `prerelease-deps = "^0.1.0"`
candidate versions found which didn't match: 0.0.1
candidate versions found which didn't match: 0.1.1-pre1, 0.0.1
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.1.0 [..]`
perhaps a crate was updated and forgotten to be re-vendored?"#,
Expand Down
6 changes: 2 additions & 4 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1756,10 +1756,8 @@ fn use_semver_package_incorrectly() {
.with_status(101)
.with_stderr(
"\
error: no matching package found
searched package name: `a`
prerelease package needs to be specified explicitly
a = { version = \"0.1.1-alpha.0\" }
error: failed to select a version for the requirement `a = \"^0.1\"`
candidate versions found which didn't match: 0.1.1-alpha.0
location searched: [..]
required by package `b v0.1.0 ([..])`
",
Expand Down

0 comments on commit 7880215

Please sign in to comment.