Skip to content

fix error message trying patch non-existing package with prerelease #12316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
@@ -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<Platform>) -> &mut Dependency {
Rc::make_mut(&mut self.inner).platform = platform;
self
3 changes: 1 addition & 2 deletions src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
@@ -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) {
41 changes: 40 additions & 1 deletion tests/testsuite/patch.rs
Original file line number Diff line number Diff line change
@@ -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();
}