Skip to content

Commit 15c7c08

Browse files
committed
Use locked_version more
1 parent 5f611af commit 15c7c08

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/cargo/core/resolver/errors.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,15 @@ pub(super) fn activation_error(
9595

9696
msg.push_str("\nversions that meet the requirements `");
9797
msg.push_str(&dep.version_req().to_string());
98-
msg.push_str("` are: ");
98+
msg.push_str("` ");
99+
100+
if let Some(v) = dep.version_req().locked_version() {
101+
msg.push_str("(locked to ");
102+
msg.push_str(&v.to_string());
103+
msg.push_str(") ");
104+
}
105+
106+
msg.push_str("are: ");
99107
msg.push_str(
100108
&candidates
101109
.iter()
@@ -239,12 +247,19 @@ pub(super) fn activation_error(
239247
versions.join(", ")
240248
};
241249

250+
let locked_version = dep
251+
.version_req()
252+
.locked_version()
253+
.map(|v| format!(" (locked to {})", v))
254+
.unwrap_or_default();
255+
242256
let mut msg = format!(
243-
"failed to select a version for the requirement `{} = \"{}\"`\n\
257+
"failed to select a version for the requirement `{} = \"{}\"`{}\n\
244258
candidate versions found which didn't match: {}\n\
245259
location searched: {}\n",
246260
dep.package_name(),
247261
dep.version_req(),
262+
locked_version,
248263
versions,
249264
registry.describe_source(dep.source_id()),
250265
);
@@ -254,7 +269,7 @@ pub(super) fn activation_error(
254269
// If we have a path dependency with a locked version, then this may
255270
// indicate that we updated a sub-package and forgot to run `cargo
256271
// update`. In this case try to print a helpful error!
257-
if dep.source_id().is_path() && dep.version_req().to_string().starts_with('=') {
272+
if dep.source_id().is_path() && dep.version_req().is_locked() {
258273
msg.push_str(
259274
"\nconsider running `cargo update` to update \
260275
a path dependency's locked version",

0 commit comments

Comments
 (0)