diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-07-02 11:08:21 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-02 11:08:21 -0700 |
| commit | ff1dd44b40a7243f43a8d32ba8bd6026197c320b (patch) | |
| tree | 4460cbf0a917a289d1d3744d9645c5ab131ea9df /src/libsemver | |
| parent | aa1163b92de7717eb7c5eba002b4012e0574a7fe (diff) | |
| parent | ca2778ede7c21efc3cf2e4e1152875ec09360770 (diff) | |
| download | rust-ff1dd44b40a7243f43a8d32ba8bd6026197c320b.tar.gz rust-ff1dd44b40a7243f43a8d32ba8bd6026197c320b.zip | |
Merge remote-tracking branch 'origin/master' into 0.11.0-release
Conflicts: src/libstd/lib.rs
Diffstat (limited to 'src/libsemver')
| -rw-r--r-- | src/libsemver/lib.rs | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/src/libsemver/lib.rs b/src/libsemver/lib.rs index c36de052cb4..fc8aa8ac257 100644 --- a/src/libsemver/lib.rs +++ b/src/libsemver/lib.rs @@ -55,12 +55,12 @@ pub enum Identifier { impl cmp::PartialOrd for Identifier { #[inline] - fn lt(&self, other: &Identifier) -> bool { + fn partial_cmp(&self, other: &Identifier) -> Option<Ordering> { match (self, other) { - (&Numeric(a), &Numeric(b)) => a < b, - (&Numeric(_), _) => true, - (&AlphaNumeric(ref a), &AlphaNumeric(ref b)) => *a < *b, - (&AlphaNumeric(_), _) => false + (&Numeric(a), &Numeric(ref b)) => a.partial_cmp(b), + (&Numeric(_), _) => Some(Less), + (&AlphaNumeric(ref a), &AlphaNumeric(ref b)) => a.partial_cmp(b), + (&AlphaNumeric(_), _) => Some(Greater) } } } @@ -130,30 +130,31 @@ impl cmp::PartialEq for Version { impl cmp::PartialOrd for Version { #[inline] - fn lt(&self, other: &Version) -> bool { - - self.major < other.major || - - (self.major == other.major && - self.minor < other.minor) || - - (self.major == other.major && - self.minor == other.minor && - self.patch < other.patch) || - - (self.major == other.major && - self.minor == other.minor && - self.patch == other.patch && - // NB: semver spec says 0.0.0-pre < 0.0.0 - // but the version of ord defined for vec - // says that [] < [pre], so we alter it - // here. - (match (self.pre.len(), other.pre.len()) { - (0, 0) => false, - (0, _) => false, - (_, 0) => true, - (_, _) => self.pre < other.pre - })) + fn partial_cmp(&self, other: &Version) -> Option<Ordering> { + match self.major.partial_cmp(&other.major) { + Some(Equal) => {} + r => return r, + } + + match self.minor.partial_cmp(&other.minor) { + Some(Equal) => {} + r => return r, + } + + match self.patch.partial_cmp(&other.patch) { + Some(Equal) => {} + r => return r, + } + + // NB: semver spec says 0.0.0-pre < 0.0.0 + // but the version of ord defined for vec + // says that [] < [pre] so we alter it here + match (self.pre.len(), other.pre.len()) { + (0, 0) => Some(Equal), + (0, _) => Some(Greater), + (_, 0) => Some(Less), + (_, _) => self.pre.partial_cmp(&other.pre) + } } } |
