From 910e5d977c49d1cc479d0e0d2784a0a268bc8361 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 5 Feb 2024 08:36:10 -0600 Subject: [PATCH] Add a `reason` to the `NoVersions` incompatibility (#22) --- examples/unsat_root_message_no_version.rs | 2 +- src/internal/incompatibility.rs | 6 ++---- src/report.rs | 13 ++++++------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/examples/unsat_root_message_no_version.rs b/examples/unsat_root_message_no_version.rs index 8b01bcf1..5b52358f 100644 --- a/examples/unsat_root_message_no_version.rs +++ b/examples/unsat_root_message_no_version.rs @@ -71,7 +71,7 @@ impl ReportFormatter, 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 { diff --git a/src/internal/incompatibility.rs b/src/internal/incompatibility.rs index 4288a676..fb45ca48 100644 --- a/src/internal/incompatibility.rs +++ b/src/internal/incompatibility.rs @@ -354,12 +354,10 @@ impl fmt::Display #[cfg(test)] pub mod tests { - use proptest::prelude::*; - + use super::*; use crate::range::Range; use crate::term::tests::strategy as term_strat; - - use super::*; + use proptest::prelude::*; proptest! { diff --git a/src/report.rs b/src/report.rs index b3d761a6..82eddaac 100644 --- a/src/report.rs +++ b/src/report.rs @@ -45,8 +45,8 @@ pub enum DerivationTree { /// 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), /// Incompatibility coming from the dependencies of a given package. FromDependencyOf(P, VS, P, VS), /// The package is unusable for reasons outside pubgrub. @@ -80,7 +80,7 @@ impl DerivationTree packages.insert(p); packages.insert(p2); } - External::NoVersions(p, _) + External::NoVersions(p, _, _) | External::NotRoot(p, _) | External::Custom(p, _, _) => { packages.insert(p); @@ -113,14 +113,14 @@ impl 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() @@ -144,7 +144,6 @@ impl 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( @@ -179,7 +178,7 @@ impl 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 {