Skip to content

Commit

Permalink
Add a reason to the NoVersions incompatibility (#22)
Browse files Browse the repository at this point in the history
* Add a `reason` to the `NoVersions` incompatibility

* Make optional
  • Loading branch information
zanieb authored and konstin committed May 7, 2024
1 parent 21dd744 commit 57a7a6a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/unsat_root_message_no_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ReportFormatter<Package, Range<SemanticVersion>, String> for CustomReportFo
External::NotRoot(package, version) => {
format!("we are solving dependencies of {package} {version}")
}
External::NoVersions(package, set) => {
External::NoVersions(package, set, _) => {
if set == &Range::full() {
format!("there is no available version for {package}")
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/incompatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibilit
}

/// Create an incompatibility to remember that a given set does not contain any version.
pub fn no_versions(package: P, term: Term<VS>) -> Self {
pub fn no_versions(package: P, term: Term<VS>, reason: Option<String>) -> Self {
let set = match &term {
Term::Positive(r) => r.clone(),
Term::Negative(_) => panic!("No version should have a positive term"),
};
Self {
package_terms: SmallMap::One([(package.clone(), term)]),
kind: Kind::NoVersions(package, set),
kind: Kind::NoVersions(package, set, reason),
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub enum DerivationTree<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Disp
pub enum External<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> {
/// Initial incompatibility aiming at picking the root package for the first decision.
NotRoot(P, VS::V),
/// There are no versions in the given set for this package.
NoVersions(P, VS),
/// There are no versions in the given set for this package. A string reason is included.
NoVersions(P, VS, Option<String>),
/// Incompatibility coming from the dependencies of a given package.
FromDependencyOf(P, VS, P, VS),
/// The package is unusable for reasons outside pubgrub.
Expand Down Expand Up @@ -82,7 +82,7 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> DerivationTree
packages.insert(p);
packages.insert(p2);
}
External::NoVersions(p, _)
External::NoVersions(p, _, _)
| External::NotRoot(p, _)
| External::Custom(p, _, _) => {
packages.insert(p);
Expand Down Expand Up @@ -112,14 +112,14 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> DerivationTree
Arc::make_mut(&mut derived.cause1),
Arc::make_mut(&mut derived.cause2),
) {
(DerivationTree::External(External::NoVersions(p, r)), ref mut cause2) => {
(DerivationTree::External(External::NoVersions(p, r, _)), ref mut cause2) => {
cause2.collapse_no_versions();
*self = cause2
.clone()
.merge_no_versions(p.to_owned(), r.to_owned())
.unwrap_or_else(|| self.to_owned());
}
(ref mut cause1, DerivationTree::External(External::NoVersions(p, r))) => {
(ref mut cause1, DerivationTree::External(External::NoVersions(p, r, _))) => {
cause1.collapse_no_versions();
*self = cause1
.clone()
Expand All @@ -143,7 +143,6 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> DerivationTree
DerivationTree::External(External::NotRoot(_, _)) => {
panic!("How did we end up with a NoVersions merged with a NotRoot?")
}
//
// Cannot be merged because the reason may not match
DerivationTree::External(External::NoVersions(_, _)) => None,
DerivationTree::External(External::Custom(_, r, reason)) => Some(
Expand Down Expand Up @@ -178,7 +177,7 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> fmt::Display
Self::NotRoot(package, version) => {
write!(f, "we are solving dependencies of {} {}", package, version)
}
Self::NoVersions(package, set) => {
Self::NoVersions(package, set, _) => {
if set == &VS::full() {
write!(f, "there is no available version for {}", package)
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ pub fn resolve<DP: DependencyProvider>(
// Pick the next compatible version.
let v = match decision {
None => {
let inc = Incompatibility::no_versions(next.clone(), term_intersection.clone());
let inc =
Incompatibility::no_versions(next.clone(), term_intersection.clone(), None);
state.add_incompatibility(inc);
continue;
}
Expand Down

0 comments on commit 57a7a6a

Please sign in to comment.