diff options
| author | bors <bors@rust-lang.org> | 2014-03-07 20:36:42 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-03-07 20:36:42 -0800 |
| commit | 96e8c00e95b1980c429c5cfa4aae33e3cc60f3c5 (patch) | |
| tree | 1dcb1676da02712aae8573cf3b1dabd307b92533 /src/libstd/cmp.rs | |
| parent | 4c90a7f018e19f94d7c32a96bf608fbd3ab56e12 (diff) | |
| parent | 4d7d101a76deea69e9078d9ed6bb93ecca70e52a (diff) | |
| download | rust-96e8c00e95b1980c429c5cfa4aae33e3cc60f3c5.tar.gz rust-96e8c00e95b1980c429c5cfa4aae33e3cc60f3c5.zip | |
auto merge of #12520 : thestinger/rust/cmp, r=brson
* `Ord` inherits from `Eq` * `TotalOrd` inherits from `TotalEq` * `TotalOrd` inherits from `Ord` * `TotalEq` inherits from `Eq` This is a partial implementation of #12517.
Diffstat (limited to 'src/libstd/cmp.rs')
| -rw-r--r-- | src/libstd/cmp.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/libstd/cmp.rs b/src/libstd/cmp.rs index 291f1dd04d3..6975c9da3f0 100644 --- a/src/libstd/cmp.rs +++ b/src/libstd/cmp.rs @@ -42,8 +42,12 @@ pub trait Eq { } /// Trait for equality comparisons where `a == b` and `a != b` are strict inverses. -pub trait TotalEq { - fn equals(&self, other: &Self) -> bool; +pub trait TotalEq: Eq { + /// This method must return the same value as `eq`. It exists to prevent + /// deriving `TotalEq` from fields not implementing the `TotalEq` trait. + fn equals(&self, other: &Self) -> bool { + self.eq(other) + } } macro_rules! totaleq_impl( @@ -76,7 +80,7 @@ totaleq_impl!(char) pub enum Ordering { Less = -1, Equal = 0, Greater = 1 } /// Trait for types that form a total order -pub trait TotalOrd: TotalEq { +pub trait TotalOrd: TotalEq + Ord { fn cmp(&self, other: &Self) -> Ordering; } @@ -161,7 +165,7 @@ pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering { * (cf. IEEE 754-2008 section 5.11). */ #[lang="ord"] -pub trait Ord { +pub trait Ord: Eq { fn lt(&self, other: &Self) -> bool; #[inline] fn le(&self, other: &Self) -> bool { !other.lt(self) } @@ -169,8 +173,6 @@ pub trait Ord { fn gt(&self, other: &Self) -> bool { other.lt(self) } #[inline] fn ge(&self, other: &Self) -> bool { !self.lt(other) } - - // FIXME (#12068): Add min/max/clamp default methods } /// The equivalence relation. Two values may be equivalent even if they are |
