Skip to content
Open
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
24 changes: 17 additions & 7 deletions crates/lib/src/hydrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ where
let node = graph
.entry(pkg.project.clone())
.or_insert_with(|| Box::new(Node::new(pkg.clone(), None)));
node.pkg.constraint = intersect_constraints(&node.pkg.constraint, &pkg.constraint)?;
node.pkg.constraint =
intersect_constraints(&node.pkg.constraint, &pkg.constraint, &pkg.project)?;
stack.push(node.clone());
}

Expand All @@ -56,8 +57,11 @@ where
let child_node = graph
.entry(child_pkg.project.clone())
.or_insert_with(|| Box::new(Node::new(child_pkg.clone(), Some(current.clone()))));
let intersection =
intersect_constraints(&child_node.pkg.constraint, &child_pkg.constraint);
let intersection = intersect_constraints(
&child_node.pkg.constraint,
&child_pkg.constraint,
&child_pkg.project,
);
if let Ok(constraint) = intersection {
child_node.pkg.constraint = constraint;
current.children.insert(child_node.pkg.project.clone());
Expand Down Expand Up @@ -94,8 +98,9 @@ fn condense(pkgs: &Vec<PackageReq>) -> Vec<PackageReq> {
let mut out: Vec<PackageReq> = vec![];
for pkg in pkgs {
if let Some(existing) = out.iter_mut().find(|p| p.project == pkg.project) {
existing.constraint = intersect_constraints(&existing.constraint, &pkg.constraint)
.expect("Failed to intersect constraints");
existing.constraint =
intersect_constraints(&existing.constraint, &pkg.constraint, &pkg.project)
.expect("Failed to intersect constraints");
} else {
out.push(pkg.clone());
}
Expand All @@ -104,6 +109,11 @@ fn condense(pkgs: &Vec<PackageReq>) -> Vec<PackageReq> {
}

/// Intersects two version constraints.
fn intersect_constraints(a: &VersionReq, b: &VersionReq) -> Result<VersionReq, Box<dyn Error>> {
a.intersect(b).map_err(|e| e.into())
fn intersect_constraints(
a: &VersionReq,
b: &VersionReq,
project_name: &str,
) -> Result<VersionReq, Box<dyn Error>> {
a.intersect(b)
.map_err(|e| format!("{} for {}: {} and {}", e, project_name, a, b).into())
}
Loading