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

Suggest "update -p" to fix a bad lockfile #5809

Closed
wants to merge 2 commits into from
Closed
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
18 changes: 12 additions & 6 deletions src/cargo/core/resolver/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,24 @@ impl EncodableResolve {
(live_pkgs, all_pkgs)
};

let lookup_id = |enc_id: &EncodablePackageId| -> CargoResult<Option<PackageId>> {
let lookup_id = |enc_id: &EncodablePackageId,
dependent_pkg: Option<&PackageId>|
-> CargoResult<Option<PackageId>> {
match live_pkgs.get(enc_id) {
Some(&(ref id, _)) => Ok(Some(id.clone())),
None => if all_pkgs.contains(enc_id) {
// Package is found in the lockfile, but it is
// no longer a member of the workspace.
Ok(None)
} else {
let suggestion = dependent_pkg
.map(|p| format!("\n consider running 'cargo update -p {}'", p.name()))
.unwrap_or_default();
bail!(
"package `{}` is specified as a dependency, \
but is missing from the package list",
enc_id
but is missing from the package list{}",
enc_id,
suggestion,
);
},
}
Expand All @@ -105,7 +111,7 @@ impl EncodableResolve {
};

for edge in deps.iter() {
if let Some(to_depend_on) = lookup_id(edge)? {
if let Some(to_depend_on) = lookup_id(edge, Some(id))? {
g.link(id.clone(), to_depend_on);
}
}
Expand All @@ -118,7 +124,7 @@ impl EncodableResolve {
for &(ref id, pkg) in live_pkgs.values() {
if let Some(ref replace) = pkg.replace {
assert!(pkg.dependencies.is_none());
if let Some(replace_id) = lookup_id(replace)? {
if let Some(replace_id) = lookup_id(replace, Some(id))? {
replacements.insert(id.clone(), replace_id);
}
}
Expand Down Expand Up @@ -151,7 +157,7 @@ impl EncodableResolve {
let k = &k[prefix.len()..];
let enc_id: EncodablePackageId = k.parse()
.chain_err(|| internal("invalid encoding of checksum in lockfile"))?;
let id = match lookup_id(&enc_id) {
let id = match lookup_id(&enc_id, None) {
Ok(Some(id)) => id,
_ => continue,
};
Expand Down
14 changes: 14 additions & 0 deletions tests/testsuite/bad_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,20 @@ fn bad_dependency_in_lockfile() {

Caused by:
package `bar 0.1.0 ([..])` is specified as a dependency, but is missing from the package list
consider running 'cargo update -p foo'
",
),
);

assert_that(
p.cargo("build").arg("-v"),
execs().with_status(101).with_stderr(
"\
[ERROR] failed to parse lock file at: [..]

Caused by:
package `bar 0.1.0 ([..])` is specified as a dependency, but is missing from the package list
consider running 'cargo update -p foo'
",
),
);
Expand Down