Skip to content

Commit 6fd11a7

Browse files
committed
Don't include a special-case error for a locked patch matching 0 entries.
1 parent 2c0cd97 commit 6fd11a7

File tree

2 files changed

+44
-63
lines changed

2 files changed

+44
-63
lines changed

src/cargo/core/registry.rs

Lines changed: 42 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -772,78 +772,59 @@ fn summary_for_patch(
772772
}
773773
assert!(summaries.is_empty());
774774
// No summaries found, try to help the user figure out what is wrong.
775-
if let Some((locked_patch, locked_id)) = locked {
775+
if let Some((_locked_patch, locked_id)) = locked {
776776
// Since the locked patch did not match anything, try the unlocked one.
777-
let mut orig_matches = source.query_vec(orig_patch).unwrap_or_else(|e| {
777+
let orig_matches = source.query_vec(orig_patch).unwrap_or_else(|e| {
778778
log::warn!(
779779
"could not determine unlocked summaries for dep {:?}: {:?}",
780780
orig_patch,
781781
e
782782
);
783783
Vec::new()
784784
});
785-
if orig_matches.is_empty() {
786-
// This should be relatively unusual. For example, a patch of
787-
// {version="0.1.2", ...} and the patch location no longer contains a
788-
// version that matches "0.1.2". It is unusual to explicitly write a
789-
// version in the patch.
790-
anyhow::bail!(
791-
"The patch is locked to {} in Cargo.lock, but the version in the \
792-
patch location does not match any packages in the patch location.\n\
793-
Make sure the patch points to the correct version.",
794-
locked_patch.version_req(),
795-
);
796-
}
797-
let summary = best_summary(&mut orig_matches);
798-
debug!(
799-
"locked patch no longer matches, but unlocked version should work. \
800-
locked={:?} unlocked={:?} summary={:?}",
801-
locked, orig_patch, summary
802-
);
785+
let (summary, _) = summary_for_patch(orig_patch, &None, orig_matches, source)?;
803786
// The unlocked version found a match. This returns a value to
804787
// indicate that this entry should be unlocked.
805788
return Ok((summary, Some(*locked_id)));
806-
} else {
807-
// Try checking if there are *any* packages that match this by name.
808-
let name_only_dep =
809-
Dependency::new_override(orig_patch.package_name(), orig_patch.source_id());
810-
let name_summaries = source.query_vec(&name_only_dep).unwrap_or_else(|e| {
811-
log::warn!(
812-
"failed to do name-only summary query for {:?}: {:?}",
813-
name_only_dep,
814-
e
815-
);
816-
Vec::new()
817-
});
818-
let mut vers = name_summaries
819-
.iter()
820-
.map(|summary| summary.version())
821-
.collect::<Vec<_>>();
822-
let found = match vers.len() {
823-
0 => format!(""),
824-
1 => format!("version `{}`", vers[0]),
825-
_ => {
826-
vers.sort();
827-
let strs: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect();
828-
format!("versions `{}`", strs.join(", "))
829-
}
830-
};
831-
if found.is_empty() {
832-
anyhow::bail!(
833-
"The patch location does not appear to contain any packages \
834-
matching the name `{}`.",
835-
orig_patch.package_name()
836-
);
837-
} else {
838-
anyhow::bail!(
839-
"The patch location contains a `{}` package with {}, but the patch \
840-
definition requires `{}`.\n\
841-
Check that the version in the patch location is what you expect, \
842-
and update the patch definition to match.",
843-
orig_patch.package_name(),
844-
found,
845-
orig_patch.version_req()
846-
);
789+
}
790+
// Try checking if there are *any* packages that match this by name.
791+
let name_only_dep = Dependency::new_override(orig_patch.package_name(), orig_patch.source_id());
792+
let name_summaries = source.query_vec(&name_only_dep).unwrap_or_else(|e| {
793+
log::warn!(
794+
"failed to do name-only summary query for {:?}: {:?}",
795+
name_only_dep,
796+
e
797+
);
798+
Vec::new()
799+
});
800+
let mut vers = name_summaries
801+
.iter()
802+
.map(|summary| summary.version())
803+
.collect::<Vec<_>>();
804+
let found = match vers.len() {
805+
0 => format!(""),
806+
1 => format!("version `{}`", vers[0]),
807+
_ => {
808+
vers.sort();
809+
let strs: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect();
810+
format!("versions `{}`", strs.join(", "))
847811
}
812+
};
813+
if found.is_empty() {
814+
anyhow::bail!(
815+
"The patch location does not appear to contain any packages \
816+
matching the name `{}`.",
817+
orig_patch.package_name()
818+
);
819+
} else {
820+
anyhow::bail!(
821+
"The patch location contains a `{}` package with {}, but the patch \
822+
definition requires `{}`.\n\
823+
Check that the version in the patch location is what you expect, \
824+
and update the patch definition to match.",
825+
orig_patch.package_name(),
826+
found,
827+
orig_patch.version_req()
828+
);
848829
}
849830
}

tests/testsuite/patch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,8 +1763,8 @@ Caused by:
17631763
patch for `bar` in `https://github.com/rust-lang/crates.io-index` did not resolve to any crates
17641764
17651765
Caused by:
1766-
The patch is locked to = 0.1.1 in Cargo.lock, but the version in the patch location does not match any packages in the patch location.
1767-
Make sure the patch points to the correct version.
1766+
The patch location contains a `bar` package with version `0.1.0`, but the patch definition requires `^0.1.1`.
1767+
Check that the version in the patch location is what you expect, and update the patch definition to match.
17681768
",
17691769
)
17701770
.run();

0 commit comments

Comments
 (0)