diff --git a/src/cargo/core/dependency.rs b/src/cargo/core/dependency.rs index 2a7255c7f22..11192a86417 100644 --- a/src/cargo/core/dependency.rs +++ b/src/cargo/core/dependency.rs @@ -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) -> &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 3353468323e..518edba4e98 100644 --- a/src/cargo/core/resolver/errors.rs +++ b/src/cargo/core/resolver/errors.rs @@ -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) { diff --git a/tests/testsuite/patch.rs b/tests/testsuite/patch.rs index 8e93fce96da..1d7aad64732 100644 --- a/tests/testsuite/patch.rs +++ b/tests/testsuite/patch.rs @@ -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?"#, diff --git a/tests/testsuite/registry.rs b/tests/testsuite/registry.rs index 51bacc32220..1aa6f45865e 100644 --- a/tests/testsuite/registry.rs +++ b/tests/testsuite/registry.rs @@ -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 ([..])` ",