Show original version_req for locked dependency

When encounter resolver error with locked dependency, we now show
original version req along with the exact locked version.
This commit is contained in:
Weihang Lo 2021-08-28 00:17:39 +08:00
parent c6762ce470
commit d22623466d
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
3 changed files with 19 additions and 3 deletions

View File

@ -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 {

View File

@ -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();
}

View File

@ -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)`