Skip to content

Commit

Permalink
rustc: Add an "ne" method to the Eq trait, and implement it everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Sep 7, 2012
1 parent ac1f84c commit feb014e
Show file tree
Hide file tree
Showing 76 changed files with 218 additions and 60 deletions.
1 change: 1 addition & 0 deletions src/cargo/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl mode : cmp::Eq {
pure fn eq(&&other: mode) -> bool {
(self as uint) == (other as uint)
}
pure fn ne(&&other: mode) -> bool { !self.eq(other) }
}

fn opts() -> ~[getopts::Opt] {
Expand Down
1 change: 1 addition & 0 deletions src/compiletest/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ impl mode : cmp::Eq {
pure fn eq(&&other: mode) -> bool {
other as int == self as int
}
pure fn ne(&&other: mode) -> bool { !self.eq(other) }
}

type config = {
Expand Down
1 change: 1 addition & 0 deletions src/fuzzer/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ impl test_mode : cmp::Eq {
pure fn eq(&&other: test_mode) -> bool {
(self as uint) == (other as uint)
}
pure fn ne(&&other: test_mode) -> bool { !self.eq(other) }
}

fn write_file(filename: &Path, content: ~str) {
Expand Down
5 changes: 2 additions & 3 deletions src/libcore/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ fn all_values(blk: fn(v: bool)) {
pure fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }

impl bool : cmp::Eq {
pure fn eq(&&other: bool) -> bool {
self == other
}
pure fn eq(&&other: bool) -> bool { self == other }
pure fn ne(&&other: bool) -> bool { self != other }
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions src/libcore/box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pure fn ptr_eq<T>(a: @T, b: @T) -> bool {

impl<T:Eq> @const T : Eq {
pure fn eq(&&other: @const T) -> bool { *self == *other }
pure fn ne(&&other: @const T) -> bool { *self != *other }
}

impl<T:Ord> @const T : Ord {
Expand Down
1 change: 1 addition & 0 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pure fn cmp(a: char, b: char) -> int {

impl char: Eq {
pure fn eq(&&other: char) -> bool { self == other }
pure fn ne(&&other: char) -> bool { self != other }
}

#[test]
Expand Down
6 changes: 6 additions & 0 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ trait Ord {
#[lang="eq"]
trait Eq {
pure fn eq(&&other: self) -> bool;
pure fn ne(&&other: self) -> bool;
}

#[cfg(test)]
trait Eq {
pure fn eq(&&other: self) -> bool;
pure fn ne(&&other: self) -> bool;
}

pure fn lt<T: Ord>(v1: &T, v2: &T) -> bool {
Expand All @@ -45,6 +47,10 @@ pure fn eq<T: Eq>(v1: &T, v2: &T) -> bool {
v1.eq(v2)
}

pure fn ne<T: Eq>(v1: &T, v2: &T) -> bool {
v1.ne(v2)
}

pure fn ge<T: Ord>(v1: &T, v2: &T) -> bool {
v1.ge(v2)
}
Expand Down
1 change: 1 addition & 0 deletions src/libcore/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ impl<T:Eq,U:Eq> Either<T,U> : Eq {
}
}
}
pure fn ne(&&other: Either<T,U>) -> bool { !self.eq(other) }
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions src/libcore/extfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ mod rt {
(pad_float, _) => false
}
}
pure fn ne(&&other: pad_mode) -> bool { !self.eq(other) }
}

fn pad(cv: conv, &s: ~str, mode: pad_mode) -> ~str {
Expand Down
1 change: 1 addition & 0 deletions src/libcore/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ pure fn tan(x: float) -> float { f64::tan(x as f64) as float }

impl float: Eq {
pure fn eq(&&other: float) -> bool { self == other }
pure fn ne(&&other: float) -> bool { self != other }
}

impl float: Ord {
Expand Down
5 changes: 2 additions & 3 deletions src/libcore/int-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ impl T: Ord {
}

impl T: Eq {
pure fn eq(&&other: T) -> bool {
return self == other;
}
pure fn eq(&&other: T) -> bool { return self == other; }
pure fn ne(&&other: T) -> bool { return self != other; }
}

impl T: num::Num {
Expand Down
1 change: 1 addition & 0 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ impl WriterType: Eq {
(Screen, _) | (File, _) => false
}
}
pure fn ne(&&other: WriterType) -> bool { !self.eq(other) }
}

// FIXME (#2004): Seekable really should be orthogonal.
Expand Down
1 change: 1 addition & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ impl<T: Eq> Option<T> : Eq {
}
}
}
pure fn ne(&&other: Option<T>) -> bool { !self.eq(other) }
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl PosixPath : Eq {
return self.is_absolute == other.is_absolute &&
self.components == other.components;
}
pure fn ne(&&other: PosixPath) -> bool { !self.eq(other) }
}

impl WindowsPath : Eq {
Expand All @@ -78,6 +79,7 @@ impl WindowsPath : Eq {
self.is_absolute == other.is_absolute &&
self.components == other.components;
}
pure fn ne(&&other: WindowsPath) -> bool { !self.eq(other) }
}

// FIXME (#3227): when default methods in traits are working, de-duplicate
Expand Down
1 change: 1 addition & 0 deletions src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl State: Eq {
pure fn eq(&&other: State) -> bool {
(self as uint) == (other as uint)
}
pure fn ne(&&other: State) -> bool { !self.eq(other) }
}

struct BufferHeader {
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ impl<T> *const T : Eq {
let b: uint = unsafe::reinterpret_cast(&other);
return a == b;
}
pure fn ne(&&other: *const T) -> bool { !self.eq(other) }
}

// Comparison for pointers
Expand Down Expand Up @@ -216,9 +217,8 @@ impl<T> *const T : Ord {

// Equality for region pointers
impl<T:Eq> &const T : Eq {
pure fn eq(&&other: &const T) -> bool {
return *self == *other;
}
pure fn eq(&&other: &const T) -> bool { return *self == *other; }
pure fn ne(&&other: &const T) -> bool { return *self != *other; }
}

// Comparison for region pointers
Expand Down
1 change: 1 addition & 0 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ impl<T:Eq,U:Eq> Result<T,U> : Eq {
}
}
}
pure fn ne(&&other: Result<T,U>) -> bool { !self.eq(other) }
}

#[cfg(test)]
Expand Down
6 changes: 6 additions & 0 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,20 +780,26 @@ impl &str: Eq {
pure fn eq(&&other: &str) -> bool {
eq_slice(self, other)
}
#[inline(always)]
pure fn ne(&&other: &str) -> bool { !self.eq(other) }
}

impl ~str: Eq {
#[inline(always)]
pure fn eq(&&other: ~str) -> bool {
eq_slice(self, other)
}
#[inline(always)]
pure fn ne(&&other: ~str) -> bool { !self.eq(other) }
}

impl @str: Eq {
#[inline(always)]
pure fn eq(&&other: @str) -> bool {
eq_slice(self, other)
}
#[inline(always)]
pure fn ne(&&other: @str) -> bool { !self.eq(other) }
}

impl ~str : Ord {
Expand Down
8 changes: 5 additions & 3 deletions src/libcore/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ enum Task {
}

impl Task : cmp::Eq {
pure fn eq(&&other: Task) -> bool {
*self == *other
}
pure fn eq(&&other: Task) -> bool { *self == *other }
pure fn ne(&&other: Task) -> bool { !self.eq(other) }
}

/**
Expand All @@ -113,6 +112,7 @@ impl TaskResult: Eq {
(Success, _) | (Failure, _) => false
}
}
pure fn ne(&&other: TaskResult) -> bool { !self.eq(other) }
}

/// A message type for notifying of task lifecycle events
Expand All @@ -131,6 +131,7 @@ impl Notification : cmp::Eq {
}
}
}
pure fn ne(&&other: Notification) -> bool { !self.eq(other) }
}

/// Scheduler modes
Expand Down Expand Up @@ -1324,6 +1325,7 @@ impl LocalData: Eq {
let ptr_b: (uint, uint) = unsafe::reinterpret_cast(&other);
return ptr_a == ptr_b;
}
pure fn ne(&&other: LocalData) -> bool { !self.eq(other) }
}

// We use dvec because it's the best data structure in core. If TLS is used
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl<A: Eq, B: Eq> (A, B): Eq {
}
}
}
pure fn ne(&&other: (A, B)) -> bool { !self.eq(other) }
}

impl<A: Ord, B: Ord> (A, B): Ord {
Expand Down Expand Up @@ -119,6 +120,7 @@ impl<A: Eq, B: Eq, C: Eq> (A, B, C): Eq {
}
}
}
pure fn ne(&&other: (A, B, C)) -> bool { !self.eq(other) }
}

impl<A: Ord, B: Ord, C: Ord> (A, B, C): Ord {
Expand Down
5 changes: 2 additions & 3 deletions src/libcore/uint-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ impl T: Ord {
}

impl T: Eq {
pure fn eq(&&other: T) -> bool {
return self == other;
}
pure fn eq(&&other: T) -> bool { return self == other; }
pure fn ne(&&other: T) -> bool { return self != other; }
}

impl T: num::Num {
Expand Down
1 change: 1 addition & 0 deletions src/libcore/uniq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use cmp::{Eq, Ord};

impl<T:Eq> ~const T : Eq {
pure fn eq(&&other: ~const T) -> bool { *self == *other }
pure fn ne(&&other: ~const T) -> bool { *self != *other }
}

impl<T:Ord> ~const T : Ord {
Expand Down
1 change: 1 addition & 0 deletions src/libcore/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cmp::{Eq, Ord};

impl () : Eq {
pure fn eq(&&_other: ()) -> bool { true }
pure fn ne(&&_other: ()) -> bool { false }
}

impl () : Ord {
Expand Down
18 changes: 9 additions & 9 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,23 +1406,23 @@ pure fn eq<T: Eq>(a: &[T], b: &[T]) -> bool {

impl<T: Eq> &[T]: Eq {
#[inline(always)]
pure fn eq(&&other: &[T]) -> bool {
eq(self, other)
}
pure fn eq(&&other: &[T]) -> bool { eq(self, other) }
#[inline(always)]
pure fn ne(&&other: &[T]) -> bool { !self.eq(other) }
}

impl<T: Eq> ~[T]: Eq {
#[inline(always)]
pure fn eq(&&other: ~[T]) -> bool {
eq(self, other)
}
pure fn eq(&&other: ~[T]) -> bool { eq(self, other) }
#[inline(always)]
pure fn ne(&&other: ~[T]) -> bool { !self.eq(other) }
}

impl<T: Eq> @[T]: Eq {
#[inline(always)]
pure fn eq(&&other: @[T]) -> bool {
eq(self, other)
}
pure fn eq(&&other: @[T]) -> bool { eq(self, other) }
#[inline(always)]
pure fn ne(&&other: @[T]) -> bool { !self.eq(other) }
}

// Lexicographical comparison
Expand Down
3 changes: 3 additions & 0 deletions src/libstd/getopts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ impl Name : Eq {
}
}
}
pure fn ne(&&other: Name) -> bool { !self.eq(other) }
}

impl Occur : Eq {
pure fn eq(&&other: Occur) -> bool {
(self as uint) == (other as uint)
}
pure fn ne(&&other: Occur) -> bool { !self.eq(other) }
}

/// Create an option that is required and takes an argument
Expand Down Expand Up @@ -449,6 +451,7 @@ impl FailType : Eq {
pure fn eq(&&other: FailType) -> bool {
(self as uint) == (other as uint)
}
pure fn ne(&&other: FailType) -> bool { !self.eq(other) }
}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,12 @@ impl Error : Eq {
self.col == other.col &&
self.msg == other.msg
}
pure fn ne(&&other: Error) -> bool { !self.eq(other) }
}

impl Json : Eq {
pure fn eq(&&other: Json) -> bool {
eq(self, other)
}
pure fn eq(&&other: Json) -> bool { eq(self, other) }
pure fn ne(&&other: Json) -> bool { !self.eq(other) }
}

trait ToJson { fn to_json() -> Json; }
Expand Down
1 change: 1 addition & 0 deletions src/libstd/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ impl<T:Eq> List<T> : Eq {
}
}
}
pure fn ne(&&other: List<T>) -> bool { !self.eq(other) }
}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/net_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ impl UserInfo : Eq {
pure fn eq(&&other: UserInfo) -> bool {
self.user == other.user && self.pass == other.pass
}
pure fn ne(&&other: UserInfo) -> bool { !self.eq(other) }
}

fn query_from_str(rawquery: &str) -> Query {
Expand Down Expand Up @@ -386,6 +387,7 @@ impl Input: Eq {
(Unreserved, _) => false
}
}
pure fn ne(&&other: Input) -> bool { !self.eq(other) }
}

// returns userinfo, host, port, and unparsed part, or an error
Expand Down
1 change: 1 addition & 0 deletions src/libstd/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl TestResult : Eq {
pure fn eq(&&other: TestResult) -> bool {
(self as uint) == (other as uint)
}
pure fn ne(&&other: TestResult) -> bool { !self.eq(other) }
}

type ConsoleTestState =
Expand Down
Loading

0 comments on commit feb014e

Please sign in to comment.