Skip to content

Commit 65e108d

Browse files
authored
Improve Term documentation (#264)
1 parent 8c37699 commit 65e108d

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/term.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ use crate::VersionSet;
99

1010
/// A positive or negative expression regarding a set of versions.
1111
///
12-
/// If a version is selected then `Positive(r)` and `Negative(r.complement())` are equivalent, but
13-
/// they have different semantics when no version is selected. A `Positive` term in the partial
14-
/// solution requires a version to be selected. But a `Negative` term allows for a solution that
15-
/// does not have that package selected. Specifically, `Positive(VS::empty())` means that there was
16-
/// a conflict, we need to select a version for the package but can't pick any, while
17-
/// `Negative(VS::full())` would mean it is fine as long as we don't select the package.
12+
/// `Positive(r)` and `Negative(r.complement())` are not equivalent:
13+
/// * the term `Positive(r)` is satisfied if the package is selected AND the selected version is in `r`.
14+
/// * the term `Negative(r.complement())` is satisfied if the package is not selected OR the selected version is in `r`.
15+
///
16+
/// A `Positive` term in the partial solution requires a version to be selected, but a `Negative` term
17+
/// allows for a solution that does not have that package selected.
18+
/// Specifically, `Positive(VS::empty())` means that there was a conflict (we need to select a version for the package
19+
/// but can't pick any), while `Negative(VS::full())` would mean it is fine as long as we don't select the package.
1820
#[derive(Debug, Clone, Eq, PartialEq)]
1921
pub enum Term<VS: VersionSet> {
20-
/// For example, "1.0.0 <= v < 2.0.0" is a positive expression
22+
/// For example, `1.0.0 <= v < 2.0.0` is a positive expression
2123
/// that is evaluated true if a version is selected
2224
/// and comprised between version 1.0.0 and version 2.0.0.
2325
Positive(VS),
24-
/// The term "not v < 3.0.0" is a negative expression
25-
/// that is evaluated true if a version is selected >= 3.0.0
26+
/// The term `not (v < 3.0.0)` is a negative expression
27+
/// that is evaluated true if a version >= 3.0.0 is selected
2628
/// or if no version is selected at all.
2729
Negative(VS),
2830
}
@@ -93,7 +95,8 @@ impl<VS: VersionSet> Term<VS> {
9395
impl<VS: VersionSet> Term<VS> {
9496
/// Compute the intersection of two terms.
9597
///
96-
/// The intersection is positive if at least one of the two terms is positive.
98+
/// The intersection is negative (unselected package is allowed)
99+
/// if all terms are negative.
97100
pub(crate) fn intersection(&self, other: &Self) -> Self {
98101
match (self, other) {
99102
(Self::Positive(r1), Self::Positive(r2)) => Self::Positive(r1.intersection(r2)),
@@ -110,7 +113,8 @@ impl<VS: VersionSet> Term<VS> {
110113
pub(crate) fn is_disjoint(&self, other: &Self) -> bool {
111114
match (self, other) {
112115
(Self::Positive(r1), Self::Positive(r2)) => r1.is_disjoint(r2),
113-
(Self::Negative(r1), Self::Negative(r2)) => r1 == &VS::empty() && r2 == &VS::empty(),
116+
// Unselected package is allowed in both terms, so they are never disjoint.
117+
(Self::Negative(_), Self::Negative(_)) => false,
114118
// If the positive term is a subset of the negative term, it lies fully in the region that the negative
115119
// term excludes.
116120
(Self::Positive(p), Self::Negative(n)) | (Self::Negative(n), Self::Positive(p)) => {
@@ -120,7 +124,7 @@ impl<VS: VersionSet> Term<VS> {
120124
}
121125

122126
/// Compute the union of two terms.
123-
/// If at least one term is negative, the union is also negative.
127+
/// If at least one term is negative, the union is also negative (unselected package is allowed).
124128
pub(crate) fn union(&self, other: &Self) -> Self {
125129
match (self, other) {
126130
(Self::Positive(r1), Self::Positive(r2)) => Self::Positive(r1.union(r2)),
@@ -138,6 +142,8 @@ impl<VS: VersionSet> Term<VS> {
138142
match (self, other) {
139143
(Self::Positive(r1), Self::Positive(r2)) => r1.subset_of(r2),
140144
(Self::Positive(r1), Self::Negative(r2)) => r1.is_disjoint(r2),
145+
// Only a negative term allows the unselected package,
146+
// so it can never be a subset of a positive term.
141147
(Self::Negative(_), Self::Positive(_)) => false,
142148
(Self::Negative(r1), Self::Negative(r2)) => r2.subset_of(r1),
143149
}

version-ranges/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ impl<'de, V: serde::Deserialize<'de>> serde::Deserialize<'de> for Ranges<V> {
898898
pub fn proptest_strategy() -> impl Strategy<Value = Ranges<u32>> {
899899
(
900900
any::<bool>(),
901-
prop::collection::vec(any::<(u32, bool)>(), 1..10),
901+
prop::collection::vec(any::<(u32, bool)>(), 0..10),
902902
)
903903
.prop_map(|(start_unbounded, deltas)| {
904904
let mut start = if start_unbounded {

0 commit comments

Comments
 (0)