]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #14492 : alexcrichton/rust/totaleq, r=pnkfelix
authorbors <bors@rust-lang.org>
Thu, 29 May 2014 17:01:37 +0000 (10:01 -0700)
committerbors <bors@rust-lang.org>
Thu, 29 May 2014 17:01:37 +0000 (10:01 -0700)
This is a transitionary step towards completing #12517. This change modifies the
compiler to accept Partial{Ord,Eq} as deriving modes which will currently expand
to implementations of PartialOrd and PartialEq (synonyms for Eq/Ord).

After a snapshot, all of deriving(Eq, Ord) will be removed, and after a snapshot
of that, TotalEq/TotalOrd will be renamed to Eq/Ord.

1  2 
src/libcore/cmp.rs

diff --combined src/libcore/cmp.rs
index 1c621f7f4ce154992c27e345711d4bffa7dc8464,dc8c2ac68b2f564d684b1f09ea9209ac1fc248e5..32fc3331fa2f771c6329091710adce9d096c328e
@@@ -37,6 -37,9 +37,9 @@@
  //! assert!(SketchyNum {num: 25} != SketchyNum {num: 57});
  //! ```
  
+ pub use PartialEq = cmp::Eq;
+ pub use PartialOrd = cmp::Ord;
  /// Trait for values that can be compared for equality and inequality.
  ///
  /// This trait allows partial equality, where types can be unordered instead of
@@@ -189,21 -192,10 +192,21 @@@ pub fn max<T: TotalOrd>(v1: T, v2: T) -
      if v1 > v2 { v1 } else { v2 }
  }
  
 -// Implementation of Eq/TotalEq for some primitive types
 +// Implementation of Eq, TotalEq, Ord and TotalOrd for primitive types
  #[cfg(not(test))]
  mod impls {
 -    use cmp::{Ord, TotalOrd, Eq, TotalEq, Ordering, Equal};
 +    use cmp::{Ord, TotalOrd, Eq, TotalEq, Ordering, Less, Greater, Equal};
 +
 +    macro_rules! eq_impl(
 +        ($($t:ty)*) => ($(
 +            impl Eq for $t {
 +                #[inline]
 +                fn eq(&self, other: &$t) -> bool { (*self) == (*other) }
 +                #[inline]
 +                fn ne(&self, other: &$t) -> bool { (*self) != (*other) }
 +            }
 +        )*)
 +    )
  
      impl Eq for () {
          #[inline]
          #[inline]
          fn ne(&self, _other: &()) -> bool { false }
      }
 -    impl TotalEq for () {}
 +
 +    eq_impl!(bool char uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
 +
 +    macro_rules! totaleq_impl(
 +        ($($t:ty)*) => ($(
 +            impl TotalEq for $t {}
 +        )*)
 +    )
 +
 +    totaleq_impl!(() bool char uint u8 u16 u32 u64 int i8 i16 i32 i64)
 +
 +    macro_rules! ord_impl(
 +        ($($t:ty)*) => ($(
 +            impl Ord for $t {
 +                #[inline]
 +                fn lt(&self, other: &$t) -> bool { (*self) < (*other) }
 +                #[inline]
 +                fn le(&self, other: &$t) -> bool { (*self) <= (*other) }
 +                #[inline]
 +                fn ge(&self, other: &$t) -> bool { (*self) >= (*other) }
 +                #[inline]
 +                fn gt(&self, other: &$t) -> bool { (*self) > (*other) }
 +            }
 +        )*)
 +    )
 +
      impl Ord for () {
          #[inline]
          fn lt(&self, _other: &()) -> bool { false }
      }
 +
 +    impl Ord for bool {
 +        #[inline]
 +        fn lt(&self, other: &bool) -> bool {
 +            (*self as u8) < (*other as u8)
 +        }
 +    }
 +
 +    ord_impl!(char uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64)
 +
 +    macro_rules! totalord_impl(
 +        ($($t:ty)*) => ($(
 +            impl TotalOrd for $t {
 +                #[inline]
 +                fn cmp(&self, other: &$t) -> Ordering {
 +                    if *self < *other { Less }
 +                    else if *self > *other { Greater }
 +                    else { Equal }
 +                }
 +            }
 +        )*)
 +    )
 +
      impl TotalOrd for () {
          #[inline]
          fn cmp(&self, _other: &()) -> Ordering { Equal }
      }
  
 +    impl TotalOrd for bool {
 +        #[inline]
 +        fn cmp(&self, other: &bool) -> Ordering {
 +            (*self as u8).cmp(&(*other as u8))
 +        }
 +    }
 +
 +    totalord_impl!(char uint u8 u16 u32 u64 int i8 i16 i32 i64)
 +
      // & pointers
      impl<'a, T: Eq> Eq for &'a T {
          #[inline]