@@ -14,21 +14,25 @@ impl Semver {
1414 self . compare ( other) == Ordering :: Less
1515 }
1616
17+ // Treat majors >1996 as calver, and less than 0.0.0.
18+ fn handle_calver ( & self ) -> Vec < usize > {
19+ if self . major < 1996 || self . major == usize:: MAX {
20+ self . components . clone ( )
21+ } else {
22+ let mut cmps = vec ! [ 0 , 0 , 0 ] ;
23+ cmps. extend ( self . components . iter ( ) . cloned ( ) ) ;
24+ cmps
25+ }
26+ }
27+
1728 fn compare ( & self , other : & Semver ) -> Ordering {
18- let len = self . components . len ( ) . max ( other. components . len ( ) ) ;
29+ let acmps = self . handle_calver ( ) ;
30+ let bcmps = other. handle_calver ( ) ;
31+
32+ let len = acmps. len ( ) . max ( bcmps. len ( ) ) ;
1933 for x in 0 ..len {
20- if x == 0 {
21- match (
22- self . major > 1900 && self . major < usize:: MAX ,
23- other. major > 1900 && other. major < usize:: MAX ,
24- ) {
25- ( true , false ) => return Ordering :: Less ,
26- ( false , true ) => return Ordering :: Greater ,
27- _ => ( ) ,
28- }
29- }
30- let a = self . components . get ( x) ;
31- let b = other. components . get ( x) ;
34+ let a = acmps. get ( x) ;
35+ let b = bcmps. get ( x) ;
3236 match ( a, b) {
3337 ( None , _) => return Ordering :: Less ,
3438 ( _, None ) => return Ordering :: Greater ,
0 commit comments