Skip to content
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

Use locked_version more #10449

Merged
merged 2 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
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
21 changes: 18 additions & 3 deletions src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,15 @@ pub(super) fn activation_error(

msg.push_str("\nversions that meet the requirements `");
msg.push_str(&dep.version_req().to_string());
msg.push_str("` are: ");
msg.push_str("` ");

if let Some(v) = dep.version_req().locked_version() {
msg.push_str("(locked to ");
msg.push_str(&v.to_string());
msg.push_str(") ");
}

msg.push_str("are: ");
msg.push_str(
&candidates
.iter()
Expand Down Expand Up @@ -239,12 +247,19 @@ pub(super) fn activation_error(
versions.join(", ")
};

let locked_version = dep
.version_req()
.locked_version()
.map(|v| format!(" (locked to {})", v))
.unwrap_or_default();

let mut msg = format!(
"failed to select a version for the requirement `{} = \"{}\"`\n\
"failed to select a version for the requirement `{} = \"{}\"`{}\n\
candidate versions found which didn't match: {}\n\
location searched: {}\n",
dep.package_name(),
dep.version_req(),
locked_version,
versions,
registry.describe_source(dep.source_id()),
);
Expand All @@ -254,7 +269,7 @@ pub(super) fn activation_error(
// If we have a path dependency with a locked version, then this may
// indicate that we updated a sub-package and forgot to run `cargo
// update`. In this case try to print a helpful error!
if dep.source_id().is_path() && dep.version_req().to_string().starts_with('=') {
if dep.source_id().is_path() && dep.version_req().is_locked() {
msg.push_str(
"\nconsider running `cargo update` to update \
a path dependency's locked version",
Expand Down
52 changes: 52 additions & 0 deletions tests/testsuite/lockfile_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,3 +836,55 @@ source = "git+{url}#{sha}"

assert_eq!(p.read_file("Cargo.lock"), lockfile);
}

#[cargo_test]
fn bad_data_in_lockfile_error_meg() {
Package::new("bar", "0.0.1").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.0.0"

[dependencies]
bar = "*"
"#,
)
.file("src/main.rs", "fn main() {}")
.file(
"Cargo.lock",
r#"# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "bar"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e1b9346248cf3391ead604c4407258d327c28e37209f6d56127598165165dda"

[[package]]
name = "test"
version = "0.0.0"
dependencies = [
"bar",
]"#,
)
.build();
p.cargo("build")
.with_status(101)
.with_stderr(
"\
[..]
[ERROR] failed to select a version for the requirement `bar = \"*\"` (locked to 0.1.0)
candidate versions found which didn't match: 0.0.1
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `test v0.0.0 ([..])`
perhaps a crate was updated and forgotten to be re-vendored?
",
)
.run();
}