Skip to content

Commit d226234

Browse files
committed
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.
1 parent c6762ce commit d226234

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/cargo/core/dependency.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,16 @@ impl Dependency {
339339
self
340340
}
341341

342+
/// Locks this dependency to a specified version.
343+
///
344+
/// Mainly used in dependency patching like `[patch]` or `[replace]`, which
345+
/// doesn't need to lock the entire dependency to a specific [`PackageId`].
346+
pub fn lock_version(&mut self, version: &semver::Version) -> &mut Dependency {
347+
let me = Rc::make_mut(&mut self.inner);
348+
me.req.lock_to(version);
349+
self
350+
}
351+
342352
/// Returns `true` if this is a "locked" dependency. Basically a locked
343353
/// dependency has an exact version req, but not vice versa.
344354
pub fn is_locked(&self) -> bool {

src/cargo/core/resolver/errors.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,16 @@ pub(crate) fn describe_path<'a>(
387387
} else {
388388
dep.name_in_toml().to_string()
389389
};
390+
let locked_version = dep
391+
.version_req()
392+
.locked_version()
393+
.map(|v| format!("(locked to {}) ", v))
394+
.unwrap_or_default();
395+
390396
write!(
391397
dep_path_desc,
392-
"\n ... which satisfies {}dependency `{}` of package `{}`",
393-
source_kind, requirement, pkg
398+
"\n ... which satisfies {}dependency `{}` {}of package `{}`",
399+
source_kind, requirement, locked_version, pkg
394400
)
395401
.unwrap();
396402
}

tests/testsuite/build_script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ fn links_duplicates_old_registry() {
10001000
but a native library can be linked only once
10011001
10021002
package `bar v0.1.0`
1003-
... which satisfies dependency `bar = \"=0.1.0\"` of package `foo v0.1.0 ([..]foo)`
1003+
... which satisfies dependency `bar = \"^0.1\"` (locked to 0.1.0) of package `foo v0.1.0 ([..]foo)`
10041004
links to native library `a`
10051005
10061006
package `foo v0.1.0 ([..]foo)`

0 commit comments

Comments
 (0)