Skip to content

Commit

Permalink
Show original version_req for locked dependency
Browse files Browse the repository at this point in the history
When encounter resolver error with locked dependency, we now show
original version req along with the exact locked version.
  • Loading branch information
weihanglo committed Sep 20, 2021
1 parent c6762ce commit d226234
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,16 @@ impl Dependency {
self
}

/// Locks this dependency to a specified version.
///
/// Mainly used in dependency patching like `[patch]` or `[replace]`, which
/// doesn't need to lock the entire dependency to a specific [`PackageId`].
pub fn lock_version(&mut self, version: &semver::Version) -> &mut Dependency {
let me = Rc::make_mut(&mut self.inner);
me.req.lock_to(version);
self
}

/// Returns `true` if this is a "locked" dependency. Basically a locked
/// dependency has an exact version req, but not vice versa.
pub fn is_locked(&self) -> bool {
Expand Down
10 changes: 8 additions & 2 deletions src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,16 @@ pub(crate) fn describe_path<'a>(
} else {
dep.name_in_toml().to_string()
};
let locked_version = dep
.version_req()
.locked_version()
.map(|v| format!("(locked to {}) ", v))
.unwrap_or_default();

write!(
dep_path_desc,
"\n ... which satisfies {}dependency `{}` of package `{}`",
source_kind, requirement, pkg
"\n ... which satisfies {}dependency `{}` {}of package `{}`",
source_kind, requirement, locked_version, pkg
)
.unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ fn links_duplicates_old_registry() {
but a native library can be linked only once
package `bar v0.1.0`
... which satisfies dependency `bar = \"=0.1.0\"` of package `foo v0.1.0 ([..]foo)`
... which satisfies dependency `bar = \"^0.1\"` (locked to 0.1.0) of package `foo v0.1.0 ([..]foo)`
links to native library `a`
package `foo v0.1.0 ([..]foo)`
Expand Down

0 comments on commit d226234

Please sign in to comment.