Skip to content

Commit 245e69c

Browse files
committed
add a test for shortest path
1 parent 976771d commit 245e69c

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

crates/resolver-tests/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub fn resolve_with_config_raw(
164164
// we found a case that causes a panic and did not use all of the input.
165165
// lets print the part of the input that was used for minimization.
166166
eprintln!(
167-
"{:?}",
167+
"Part used befor drop: {:?}",
168168
PrettyPrintRegistry(
169169
self.list
170170
.iter()

crates/resolver-tests/tests/resolve.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,3 +1562,37 @@ package `A v0.0.0 (registry `https://example.com/`)`
15621562
... which satisfies dependency `C = \"*\"` of package `A v0.0.0 (registry `https://example.com/`)`\
15631563
", error.to_string());
15641564
}
1565+
1566+
#[test]
1567+
fn shortest_path_in_error_message() {
1568+
let input = vec![
1569+
pkg!(("F", "0.1.2")),
1570+
pkg!(("F", "0.1.1") => [dep("bad"),]),
1571+
pkg!(("F", "0.1.0") => [dep("bad"),]),
1572+
pkg!("E" => [dep_req("F", "^0.1.2"),]),
1573+
pkg!("D" => [dep_req("F", "^0.1.2"),]),
1574+
pkg!("C" => [dep("D"),]),
1575+
pkg!("A" => [dep("C"),dep("E"),dep_req("F", "<=0.1.1"),]),
1576+
];
1577+
let error = resolve(vec![dep("A")], &registry(input)).unwrap_err();
1578+
println!("{}", error);
1579+
assert_eq!(
1580+
"\
1581+
failed to select a version for `F`.
1582+
... required by package `A v1.0.0 (registry `https://example.com/`)`
1583+
... which satisfies dependency `A = \"*\"` of package `root v1.0.0 (registry `https://example.com/`)`
1584+
versions that meet the requirements `<=0.1.1` are: 0.1.1, 0.1.0
1585+
1586+
all possible versions conflict with previously selected packages.
1587+
1588+
previously selected package `F v0.1.2 (registry `https://example.com/`)`
1589+
... which satisfies dependency `F = \"^0.1.2\"` of package `D v1.0.0 (registry `https://example.com/`)`
1590+
... which satisfies dependency `D = \"*\"` of package `C v1.0.0 (registry `https://example.com/`)`
1591+
... which satisfies dependency `C = \"*\"` of package `A v1.0.0 (registry `https://example.com/`)`
1592+
... which satisfies dependency `A = \"*\"` of package `root v1.0.0 (registry `https://example.com/`)`
1593+
1594+
failed to select a version for `F` which could resolve this conflict\
1595+
",
1596+
error.to_string()
1597+
);
1598+
}

src/cargo/core/resolver/dep_cache.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ impl<'a> RegistryQueryer<'a> {
131131
.iter()
132132
.filter(|(spec, _)| spec.matches(summary.package_id()));
133133

134-
let (spec, dep) = match potential_matches.next() {
135-
None => continue,
136-
Some(replacement) => replacement,
134+
let Some((spec, dep)) = potential_matches.next() else {
135+
continue;
137136
};
138137
debug!(
139138
"found an override for {} {}",

0 commit comments

Comments
 (0)