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

fixes rust-lang#12315
  • Loading branch information
loloicci authored and Eh2406 committed Sep 11, 2023
1 parent bef47cb commit d89c902
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 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
41 changes: 40 additions & 1 deletion tests/testsuite/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ fn multipatch_select_big() {

// assert the build succeeds, which is only possible if 0.2.0 is selected
// since 0.1.0 is missing the function we need. Afterwards assert that the
// build succeeds again without updating anything or building anything else.
// build succeeds again without updating anything or building anything else.o
p.cargo("check").run();
p.cargo("check")
.with_stderr(
Expand Down Expand Up @@ -2658,3 +2658,42 @@ failed to select a version for `qux` which could resolve this conflict"#,
)
.run();
}

#[cargo_test]
fn mismatched_version_with_prerelease() {
// A patch to a location that has an prerelease version
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
prerelease-deps = "0.1.0"
[patch.crates-io]
prerelease-deps = { path = "./prerelease-deps" }
"#,
)
.file("src/lib.rs", "")
.file(
"prerelease-deps/Cargo.toml",
&basic_manifest("prerelease-deps", "0.1.1-pre1"),
)
.file("prerelease-deps/src/lib.rs", "")
.build();

p.cargo("generate-lockfile")
.with_status(101)
.with_stderr(
r#"[UPDATING] crates.io index
[ERROR] failed to select a version for the requirement `prerelease-deps = "^0.1.0"`
candidate versions found which didn't match: 0.1.1-pre1
location searched: crates.io index
required by package `foo v0.1.0 [..]`
perhaps a crate was updated and forgotten to be re-vendored?"#,
)
.run();
}

0 comments on commit d89c902

Please sign in to comment.