diff --git a/src/cargo/core/dependency.rs b/src/cargo/core/dependency.rs index 0b3aba8ada5..93bc0e6b3d1 100644 --- a/src/cargo/core/dependency.rs +++ b/src/cargo/core/dependency.rs @@ -324,6 +324,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) -> &mut Dependency { Rc::make_mut(&mut self.inner).platform = platform; self diff --git a/src/cargo/core/resolver/errors.rs b/src/cargo/core/resolver/errors.rs index ca5c833f4bc..81c0f0b6299 100644 --- a/src/cargo/core/resolver/errors.rs +++ b/src/cargo/core/resolver/errors.rs @@ -223,9 +223,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) { diff --git a/tests/testsuite/patch.rs b/tests/testsuite/patch.rs index f2f077d7d86..69b71d0431c 100644 --- a/tests/testsuite/patch.rs +++ b/tests/testsuite/patch.rs @@ -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( @@ -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(); +}