From b258de7bda2963a0e1940fc419011560937b2b08 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 20 Nov 2014 18:17:37 -0500 Subject: [PATCH] libcore: add `Rhs` input parameter to comparison traits --- src/libcore/cmp.rs | 24 ++++++++++++------------ src/libcore/lib.rs | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 51122d0a170..11878dc76d9 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -61,13 +61,13 @@ use option::{Option, Some, None}; /// `Eq`. #[lang="eq"] #[unstable = "Definition may change slightly after trait reform"] -pub trait PartialEq for Sized? { +pub trait PartialEq for Sized? { /// This method tests for `self` and `other` values to be equal, and is used by `==`. - fn eq(&self, other: &Self) -> bool; + fn eq(&self, other: &Rhs) -> bool; /// This method tests for `!=`. #[inline] - fn ne(&self, other: &Self) -> bool { !self.eq(other) } + fn ne(&self, other: &Rhs) -> bool { !self.eq(other) } } /// Trait for equality comparisons which are [equivalence relations]( @@ -80,7 +80,7 @@ pub trait PartialEq for Sized? { /// - symmetric: `a == b` implies `b == a`; and /// - transitive: `a == b` and `b == c` implies `a == c`. #[unstable = "Definition may change slightly after trait reform"] -pub trait Eq for Sized?: PartialEq { +pub trait Eq for Sized?: PartialEq { // FIXME #13101: this method is used solely by #[deriving] to // assert that every component of a type implements #[deriving] // itself, the current deriving infrastructure means doing this @@ -150,7 +150,7 @@ impl Ordering { /// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for /// both `==` and `>`. #[unstable = "Definition may change slightly after trait reform"] -pub trait Ord for Sized?: Eq + PartialOrd { +pub trait Ord for Sized?: Eq + PartialOrd { /// This method returns an ordering between `self` and `other` values. /// /// By convention, `self.cmp(&other)` returns the ordering matching @@ -161,7 +161,7 @@ pub trait Ord for Sized?: Eq + PartialOrd { /// assert_eq!(10u.cmp(&5), Greater); // because 10 > 5 /// assert_eq!( 5u.cmp(&5), Equal); // because 5 == 5 /// ``` - fn cmp(&self, other: &Self) -> Ordering; + fn cmp(&self, other: &Rhs) -> Ordering; } #[unstable = "Trait is unstable."] @@ -194,14 +194,14 @@ impl PartialOrd for Ordering { /// 5.11). #[lang="ord"] #[unstable = "Definition may change slightly after trait reform"] -pub trait PartialOrd for Sized?: PartialEq { +pub trait PartialOrd for Sized?: PartialEq { /// This method returns an ordering between `self` and `other` values /// if one exists. - fn partial_cmp(&self, other: &Self) -> Option; + fn partial_cmp(&self, other: &Rhs) -> Option; /// This method tests less than (for `self` and `other`) and is used by the `<` operator. #[inline] - fn lt(&self, other: &Self) -> bool { + fn lt(&self, other: &Rhs) -> bool { match self.partial_cmp(other) { Some(Less) => true, _ => false, @@ -210,7 +210,7 @@ pub trait PartialOrd for Sized?: PartialEq { /// This method tests less than or equal to (`<=`). #[inline] - fn le(&self, other: &Self) -> bool { + fn le(&self, other: &Rhs) -> bool { match self.partial_cmp(other) { Some(Less) | Some(Equal) => true, _ => false, @@ -219,7 +219,7 @@ pub trait PartialOrd for Sized?: PartialEq { /// This method tests greater than (`>`). #[inline] - fn gt(&self, other: &Self) -> bool { + fn gt(&self, other: &Rhs) -> bool { match self.partial_cmp(other) { Some(Greater) => true, _ => false, @@ -228,7 +228,7 @@ pub trait PartialOrd for Sized?: PartialEq { /// This method tests greater than or equal to (`>=`). #[inline] - fn ge(&self, other: &Self) -> bool { + fn ge(&self, other: &Rhs) -> bool { match self.partial_cmp(other) { Some(Greater) | Some(Equal) => true, _ => false, diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 56a86773060..5ad9462daf2 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -59,6 +59,7 @@ #![allow(unknown_features)] #![feature(globs, intrinsics, lang_items, macro_rules, phase)] #![feature(simd, unsafe_destructor, slicing_syntax)] +#![feature(default_type_params)] #![deny(missing_docs)] mod macros;