Skip to content

Commit 7880215

Browse files
loloicciEh2406
authored andcommitted
fix error message trying patch non-existing package with prerelease version
1 parent c29c25b commit 7880215

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/cargo/core/dependency.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ impl Dependency {
323323
self
324324
}
325325

326+
/// Sets the version requirement as any for this dependency.
327+
pub fn set_version_req_as_any(&mut self) -> &mut Dependency {
328+
Rc::make_mut(&mut self.inner).req = OptVersionReq::Any;
329+
self
330+
}
331+
326332
pub fn set_platform(&mut self, platform: Option<Platform>) -> &mut Dependency {
327333
Rc::make_mut(&mut self.inner).platform = platform;
328334
self

src/cargo/core/resolver/errors.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,8 @@ pub(super) fn activation_error(
224224
// Maybe the user mistyped the ver_req? Like `dep="2"` when `dep="0.2"`
225225
// was meant. So we re-query the registry with `dep="*"` so we can
226226
// list a few versions that were actually found.
227-
let all_req = semver::VersionReq::parse("*").unwrap();
228227
let mut new_dep = dep.clone();
229-
new_dep.set_version_req(all_req);
228+
new_dep.set_version_req_as_any();
230229

231230
let mut candidates = loop {
232231
match registry.query_vec(&new_dep, QueryKind::Exact) {

tests/testsuite/patch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ fn mismatched_version_with_prerelease() {
26912691
.with_stderr(
26922692
r#"[UPDATING] `dummy-registry` index
26932693
[ERROR] failed to select a version for the requirement `prerelease-deps = "^0.1.0"`
2694-
candidate versions found which didn't match: 0.0.1
2694+
candidate versions found which didn't match: 0.1.1-pre1, 0.0.1
26952695
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
26962696
required by package `foo v0.1.0 [..]`
26972697
perhaps a crate was updated and forgotten to be re-vendored?"#,

tests/testsuite/registry.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,10 +1756,8 @@ fn use_semver_package_incorrectly() {
17561756
.with_status(101)
17571757
.with_stderr(
17581758
"\
1759-
error: no matching package found
1760-
searched package name: `a`
1761-
prerelease package needs to be specified explicitly
1762-
a = { version = \"0.1.1-alpha.0\" }
1759+
error: failed to select a version for the requirement `a = \"^0.1\"`
1760+
candidate versions found which didn't match: 0.1.1-alpha.0
17631761
location searched: [..]
17641762
required by package `b v0.1.0 ([..])`
17651763
",

0 commit comments

Comments
 (0)