@@ -9,20 +9,22 @@ use crate::VersionSet;
9
9
10
10
/// A positive or negative expression regarding a set of versions.
11
11
///
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.
18
20
#[ derive( Debug , Clone , Eq , PartialEq ) ]
19
21
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
21
23
/// that is evaluated true if a version is selected
22
24
/// and comprised between version 1.0.0 and version 2.0.0.
23
25
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
26
28
/// or if no version is selected at all.
27
29
Negative ( VS ) ,
28
30
}
@@ -93,7 +95,8 @@ impl<VS: VersionSet> Term<VS> {
93
95
impl < VS : VersionSet > Term < VS > {
94
96
/// Compute the intersection of two terms.
95
97
///
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.
97
100
pub ( crate ) fn intersection ( & self , other : & Self ) -> Self {
98
101
match ( self , other) {
99
102
( Self :: Positive ( r1) , Self :: Positive ( r2) ) => Self :: Positive ( r1. intersection ( r2) ) ,
@@ -110,7 +113,8 @@ impl<VS: VersionSet> Term<VS> {
110
113
pub ( crate ) fn is_disjoint ( & self , other : & Self ) -> bool {
111
114
match ( self , other) {
112
115
( 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 ,
114
118
// If the positive term is a subset of the negative term, it lies fully in the region that the negative
115
119
// term excludes.
116
120
( Self :: Positive ( p) , Self :: Negative ( n) ) | ( Self :: Negative ( n) , Self :: Positive ( p) ) => {
@@ -120,7 +124,7 @@ impl<VS: VersionSet> Term<VS> {
120
124
}
121
125
122
126
/// 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) .
124
128
pub ( crate ) fn union ( & self , other : & Self ) -> Self {
125
129
match ( self , other) {
126
130
( Self :: Positive ( r1) , Self :: Positive ( r2) ) => Self :: Positive ( r1. union ( r2) ) ,
@@ -138,6 +142,8 @@ impl<VS: VersionSet> Term<VS> {
138
142
match ( self , other) {
139
143
( Self :: Positive ( r1) , Self :: Positive ( r2) ) => r1. subset_of ( r2) ,
140
144
( 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.
141
147
( Self :: Negative ( _) , Self :: Positive ( _) ) => false ,
142
148
( Self :: Negative ( r1) , Self :: Negative ( r2) ) => r2. subset_of ( r1) ,
143
149
}
0 commit comments