@@ -9,10 +9,10 @@ use std::fmt;
9
9
use crate :: internal:: arena:: { Arena , Id } ;
10
10
use crate :: internal:: small_map:: SmallMap ;
11
11
use crate :: package:: Package ;
12
- use crate :: range :: Range ;
12
+ use crate :: range_trait :: Range ;
13
13
use crate :: report:: { DefaultStringReporter , DerivationTree , Derived , External } ;
14
14
use crate :: term:: { self , Term } ;
15
- use crate :: version :: Version ;
15
+ use crate :: version_trait :: { Interval , Version } ;
16
16
17
17
/// An incompatibility is a set of terms for different packages
18
18
/// that should never be satisfied all together.
@@ -30,26 +30,26 @@ use crate::version::Version;
30
30
/// during conflict resolution. More about all this in
31
31
/// [PubGrub documentation](https://github.com/dart-lang/pub/blob/master/doc/solver.md#incompatibility).
32
32
#[ derive( Debug , Clone ) ]
33
- pub struct Incompatibility < P : Package , V : Version > {
34
- package_terms : SmallMap < P , Term < V > > ,
35
- kind : Kind < P , V > ,
33
+ pub struct Incompatibility < P : Package , I : Interval < V > , V : Version > {
34
+ package_terms : SmallMap < P , Term < I , V > > ,
35
+ kind : Kind < P , I , V > ,
36
36
}
37
37
38
38
/// Type alias of unique identifiers for incompatibilities.
39
- pub type IncompId < P , V > = Id < Incompatibility < P , V > > ;
39
+ pub type IncompId < P , I , V > = Id < Incompatibility < P , I , V > > ;
40
40
41
41
#[ derive( Debug , Clone ) ]
42
- enum Kind < P : Package , V : Version > {
42
+ enum Kind < P : Package , I : Interval < V > , V : Version > {
43
43
/// Initial incompatibility aiming at picking the root package for the first decision.
44
44
NotRoot ( P , V ) ,
45
45
/// There are no versions in the given range for this package.
46
- NoVersions ( P , Range < V > ) ,
46
+ NoVersions ( P , Range < I , V > ) ,
47
47
/// Dependencies of the package are unavailable for versions in that range.
48
- UnavailableDependencies ( P , Range < V > ) ,
48
+ UnavailableDependencies ( P , Range < I , V > ) ,
49
49
/// Incompatibility coming from the dependencies of a given package.
50
- FromDependencyOf ( P , Range < V > , P , Range < V > ) ,
50
+ FromDependencyOf ( P , Range < I , V > , P , Range < I , V > ) ,
51
51
/// Derived from two causes. Stores cause ids.
52
- DerivedFrom ( IncompId < P , V > , IncompId < P , V > ) ,
52
+ DerivedFrom ( IncompId < P , I , V > , IncompId < P , I , V > ) ,
53
53
}
54
54
55
55
/// A Relation describes how a set of terms can be compared to an incompatibility.
@@ -69,21 +69,21 @@ pub enum Relation<P: Package> {
69
69
Inconclusive ,
70
70
}
71
71
72
- impl < P : Package , V : Version > Incompatibility < P , V > {
72
+ impl < P : Package , I : Interval < V > , V : Version > Incompatibility < P , I , V > {
73
73
/// Create the initial "not Root" incompatibility.
74
74
pub fn not_root ( package : P , version : V ) -> Self {
75
75
Self {
76
76
package_terms : SmallMap :: One ( [ (
77
77
package. clone ( ) ,
78
- Term :: Negative ( Range :: exact ( version. clone ( ) ) ) ,
78
+ Term :: Negative ( Range :: singleton ( version. clone ( ) ) ) ,
79
79
) ] ) ,
80
80
kind : Kind :: NotRoot ( package, version) ,
81
81
}
82
82
}
83
83
84
84
/// Create an incompatibility to remember
85
85
/// that a given range does not contain any version.
86
- pub fn no_versions ( package : P , term : Term < V > ) -> Self {
86
+ pub fn no_versions ( package : P , term : Term < I , V > ) -> Self {
87
87
let range = match & term {
88
88
Term :: Positive ( r) => r. clone ( ) ,
89
89
Term :: Negative ( _) => panic ! ( "No version should have a positive term" ) ,
@@ -98,16 +98,16 @@ impl<P: Package, V: Version> Incompatibility<P, V> {
98
98
/// that a package version is not selectable
99
99
/// because its list of dependencies is unavailable.
100
100
pub fn unavailable_dependencies ( package : P , version : V ) -> Self {
101
- let range = Range :: exact ( version) ;
101
+ let range = Range :: singleton ( version) ;
102
102
Self {
103
103
package_terms : SmallMap :: One ( [ ( package. clone ( ) , Term :: Positive ( range. clone ( ) ) ) ] ) ,
104
104
kind : Kind :: UnavailableDependencies ( package, range) ,
105
105
}
106
106
}
107
107
108
108
/// Build an incompatibility from a given dependency.
109
- pub fn from_dependency ( package : P , version : V , dep : ( & P , & Range < V > ) ) -> Self {
110
- let range1 = Range :: exact ( version) ;
109
+ pub fn from_dependency ( package : P , version : V , dep : ( & P , & Range < I , V > ) ) -> Self {
110
+ let range1 = Range :: singleton ( version) ;
111
111
let ( p2, range2) = dep;
112
112
Self {
113
113
package_terms : SmallMap :: Two ( [
@@ -157,12 +157,12 @@ impl<P: Package, V: Version> Incompatibility<P, V> {
157
157
}
158
158
159
159
/// Get the term related to a given package (if it exists).
160
- pub fn get ( & self , package : & P ) -> Option < & Term < V > > {
160
+ pub fn get ( & self , package : & P ) -> Option < & Term < I , V > > {
161
161
self . package_terms . get ( package)
162
162
}
163
163
164
164
/// Iterate over packages.
165
- pub fn iter ( & self ) -> impl Iterator < Item = ( & P , & Term < V > ) > {
165
+ pub fn iter ( & self ) -> impl Iterator < Item = ( & P , & Term < I , V > ) > {
166
166
self . package_terms . iter ( )
167
167
}
168
168
@@ -181,7 +181,7 @@ impl<P: Package, V: Version> Incompatibility<P, V> {
181
181
self_id : Id < Self > ,
182
182
shared_ids : & Set < Id < Self > > ,
183
183
store : & Arena < Self > ,
184
- ) -> DerivationTree < P , V > {
184
+ ) -> DerivationTree < P , I , V > {
185
185
match & store[ self_id] . kind {
186
186
Kind :: DerivedFrom ( id1, id2) => {
187
187
let cause1 = Self :: build_derivation_tree ( * id1, shared_ids, store) ;
@@ -215,9 +215,9 @@ impl<P: Package, V: Version> Incompatibility<P, V> {
215
215
}
216
216
}
217
217
218
- impl < ' a , P : Package , V : Version + ' a > Incompatibility < P , V > {
218
+ impl < ' a , P : Package , I : Interval < V > + ' a , V : Version + ' a > Incompatibility < P , I , V > {
219
219
/// CF definition of Relation enum.
220
- pub fn relation ( & self , terms : impl Fn ( & P ) -> Option < & ' a Term < V > > ) -> Relation < P > {
220
+ pub fn relation ( & self , terms : impl Fn ( & P ) -> Option < & ' a Term < I , V > > ) -> Relation < P > {
221
221
let mut relation = Relation :: Satisfied ;
222
222
for ( package, incompat_term) in self . package_terms . iter ( ) {
223
223
match terms ( package) . map ( |term| incompat_term. relation_with ( & term) ) {
@@ -243,7 +243,7 @@ impl<'a, P: Package, V: Version + 'a> Incompatibility<P, V> {
243
243
}
244
244
}
245
245
246
- impl < P : Package , V : Version > fmt:: Display for Incompatibility < P , V > {
246
+ impl < P : Package , I : Interval < V > , V : Version > fmt:: Display for Incompatibility < P , I , V > {
247
247
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
248
248
write ! (
249
249
f,
@@ -276,12 +276,12 @@ pub mod tests {
276
276
let mut store = Arena :: new( ) ;
277
277
let i1 = store. alloc( Incompatibility {
278
278
package_terms: SmallMap :: Two ( [ ( "p1" , t1. clone( ) ) , ( "p2" , t2. negate( ) ) ] ) ,
279
- kind: Kind :: UnavailableDependencies ( "0" , Range :: any ( ) )
279
+ kind: Kind :: UnavailableDependencies ( "0" , Range :: full ( ) )
280
280
} ) ;
281
281
282
282
let i2 = store. alloc( Incompatibility {
283
283
package_terms: SmallMap :: Two ( [ ( "p2" , t2) , ( "p3" , t3. clone( ) ) ] ) ,
284
- kind: Kind :: UnavailableDependencies ( "0" , Range :: any ( ) )
284
+ kind: Kind :: UnavailableDependencies ( "0" , Range :: full ( ) )
285
285
} ) ;
286
286
287
287
let mut i3 = Map :: default ( ) ;
0 commit comments