Skip to content

Commit b258de7

Browse files
author
Jorge Aparicio
committed
libcore: add Rhs input parameter to comparison traits
1 parent 3a325c6 commit b258de7

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/libcore/cmp.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ use option::{Option, Some, None};
6161
/// `Eq`.
6262
#[lang="eq"]
6363
#[unstable = "Definition may change slightly after trait reform"]
64-
pub trait PartialEq for Sized? {
64+
pub trait PartialEq<Sized? Rhs = Self> for Sized? {
6565
/// This method tests for `self` and `other` values to be equal, and is used by `==`.
66-
fn eq(&self, other: &Self) -> bool;
66+
fn eq(&self, other: &Rhs) -> bool;
6767

6868
/// This method tests for `!=`.
6969
#[inline]
70-
fn ne(&self, other: &Self) -> bool { !self.eq(other) }
70+
fn ne(&self, other: &Rhs) -> bool { !self.eq(other) }
7171
}
7272

7373
/// Trait for equality comparisons which are [equivalence relations](
@@ -80,7 +80,7 @@ pub trait PartialEq for Sized? {
8080
/// - symmetric: `a == b` implies `b == a`; and
8181
/// - transitive: `a == b` and `b == c` implies `a == c`.
8282
#[unstable = "Definition may change slightly after trait reform"]
83-
pub trait Eq for Sized?: PartialEq {
83+
pub trait Eq<Sized? Rhs = Self> for Sized?: PartialEq<Rhs> {
8484
// FIXME #13101: this method is used solely by #[deriving] to
8585
// assert that every component of a type implements #[deriving]
8686
// itself, the current deriving infrastructure means doing this
@@ -150,7 +150,7 @@ impl Ordering {
150150
/// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for
151151
/// both `==` and `>`.
152152
#[unstable = "Definition may change slightly after trait reform"]
153-
pub trait Ord for Sized?: Eq + PartialOrd {
153+
pub trait Ord<Sized? Rhs = Self> for Sized?: Eq<Rhs> + PartialOrd<Rhs> {
154154
/// This method returns an ordering between `self` and `other` values.
155155
///
156156
/// By convention, `self.cmp(&other)` returns the ordering matching
@@ -161,7 +161,7 @@ pub trait Ord for Sized?: Eq + PartialOrd {
161161
/// assert_eq!(10u.cmp(&5), Greater); // because 10 > 5
162162
/// assert_eq!( 5u.cmp(&5), Equal); // because 5 == 5
163163
/// ```
164-
fn cmp(&self, other: &Self) -> Ordering;
164+
fn cmp(&self, other: &Rhs) -> Ordering;
165165
}
166166

167167
#[unstable = "Trait is unstable."]
@@ -194,14 +194,14 @@ impl PartialOrd for Ordering {
194194
/// 5.11).
195195
#[lang="ord"]
196196
#[unstable = "Definition may change slightly after trait reform"]
197-
pub trait PartialOrd for Sized?: PartialEq {
197+
pub trait PartialOrd<Sized? Rhs = Self> for Sized?: PartialEq<Rhs> {
198198
/// This method returns an ordering between `self` and `other` values
199199
/// if one exists.
200-
fn partial_cmp(&self, other: &Self) -> Option<Ordering>;
200+
fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;
201201

202202
/// This method tests less than (for `self` and `other`) and is used by the `<` operator.
203203
#[inline]
204-
fn lt(&self, other: &Self) -> bool {
204+
fn lt(&self, other: &Rhs) -> bool {
205205
match self.partial_cmp(other) {
206206
Some(Less) => true,
207207
_ => false,
@@ -210,7 +210,7 @@ pub trait PartialOrd for Sized?: PartialEq {
210210

211211
/// This method tests less than or equal to (`<=`).
212212
#[inline]
213-
fn le(&self, other: &Self) -> bool {
213+
fn le(&self, other: &Rhs) -> bool {
214214
match self.partial_cmp(other) {
215215
Some(Less) | Some(Equal) => true,
216216
_ => false,
@@ -219,7 +219,7 @@ pub trait PartialOrd for Sized?: PartialEq {
219219

220220
/// This method tests greater than (`>`).
221221
#[inline]
222-
fn gt(&self, other: &Self) -> bool {
222+
fn gt(&self, other: &Rhs) -> bool {
223223
match self.partial_cmp(other) {
224224
Some(Greater) => true,
225225
_ => false,
@@ -228,7 +228,7 @@ pub trait PartialOrd for Sized?: PartialEq {
228228

229229
/// This method tests greater than or equal to (`>=`).
230230
#[inline]
231-
fn ge(&self, other: &Self) -> bool {
231+
fn ge(&self, other: &Rhs) -> bool {
232232
match self.partial_cmp(other) {
233233
Some(Greater) | Some(Equal) => true,
234234
_ => false,

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#![allow(unknown_features)]
6060
#![feature(globs, intrinsics, lang_items, macro_rules, phase)]
6161
#![feature(simd, unsafe_destructor, slicing_syntax)]
62+
#![feature(default_type_params)]
6263
#![deny(missing_docs)]
6364

6465
mod macros;

0 commit comments

Comments
 (0)