about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-09-07 12:06:02 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-09-07 12:24:48 -0700
commitfeb014eb3c3aa1ccaae1df407801dffa090499fd (patch)
tree8ffeec6945de4843f9e0d150720596327530e00f /src/libcore
parentac1f84c153a171e641233e5d2d11404a0b520986 (diff)
downloadrust-feb014eb3c3aa1ccaae1df407801dffa090499fd.tar.gz
rust-feb014eb3c3aa1ccaae1df407801dffa090499fd.zip
rustc: Add an "ne" method to the Eq trait, and implement it everywhere
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/bool.rs5
-rw-r--r--src/libcore/box.rs1
-rw-r--r--src/libcore/char.rs1
-rw-r--r--src/libcore/cmp.rs6
-rw-r--r--src/libcore/either.rs1
-rw-r--r--src/libcore/extfmt.rs1
-rw-r--r--src/libcore/float.rs1
-rw-r--r--src/libcore/int-template.rs5
-rw-r--r--src/libcore/io.rs1
-rw-r--r--src/libcore/option.rs1
-rw-r--r--src/libcore/path.rs2
-rw-r--r--src/libcore/pipes.rs1
-rw-r--r--src/libcore/ptr.rs6
-rw-r--r--src/libcore/result.rs1
-rw-r--r--src/libcore/str.rs6
-rw-r--r--src/libcore/task.rs8
-rw-r--r--src/libcore/tuple.rs2
-rw-r--r--src/libcore/uint-template.rs5
-rw-r--r--src/libcore/uniq.rs1
-rw-r--r--src/libcore/unit.rs1
-rw-r--r--src/libcore/vec.rs18
21 files changed, 50 insertions, 24 deletions
diff --git a/src/libcore/bool.rs b/src/libcore/bool.rs
index 56d4e399cac..7deb5b30eef 100644
--- a/src/libcore/bool.rs
+++ b/src/libcore/bool.rs
@@ -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]
diff --git a/src/libcore/box.rs b/src/libcore/box.rs
index 49fd9b8706f..8629ffc78e0 100644
--- a/src/libcore/box.rs
+++ b/src/libcore/box.rs
@@ -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 {
diff --git a/src/libcore/char.rs b/src/libcore/char.rs
index 20b0857f5c8..69392d8648f 100644
--- a/src/libcore/char.rs
+++ b/src/libcore/char.rs
@@ -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]
diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs
index 6647963bc5e..82a830d05cd 100644
--- a/src/libcore/cmp.rs
+++ b/src/libcore/cmp.rs
@@ -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 {
@@ -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)
 }
diff --git a/src/libcore/either.rs b/src/libcore/either.rs
index 36fc13c12af..00706280ebc 100644
--- a/src/libcore/either.rs
+++ b/src/libcore/either.rs
@@ -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]
diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs
index 4db222ea332..731c4a6f457 100644
--- a/src/libcore/extfmt.rs
+++ b/src/libcore/extfmt.rs
@@ -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 {
diff --git a/src/libcore/float.rs b/src/libcore/float.rs
index a69260abaab..b570f1a1495 100644
--- a/src/libcore/float.rs
+++ b/src/libcore/float.rs
@@ -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 {
diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs
index 0fd8ea1d5f1..e1b592522e6 100644
--- a/src/libcore/int-template.rs
+++ b/src/libcore/int-template.rs
@@ -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 {
diff --git a/src/libcore/io.rs b/src/libcore/io.rs
index 483c96206b5..a9d83194713 100644
--- a/src/libcore/io.rs
+++ b/src/libcore/io.rs
@@ -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.
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index dfa02303751..4c4e0048f17 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -266,6 +266,7 @@ impl<T: Eq> Option<T> : Eq {
             }
         }
     }
+    pure fn ne(&&other: Option<T>) -> bool { !self.eq(other) }
 }
 
 #[test]
diff --git a/src/libcore/path.rs b/src/libcore/path.rs
index 2151fc599e6..a9dda62d950 100644
--- a/src/libcore/path.rs
+++ b/src/libcore/path.rs
@@ -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 {
@@ -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
diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs
index f0b656ea649..2078b1ed71b 100644
--- a/src/libcore/pipes.rs
+++ b/src/libcore/pipes.rs
@@ -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 {
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index c7558ffba1c..6e8a2bb3611 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -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
@@ -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
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index 5fb53b1fed4..e4028a466e0 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -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)]
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index bc669870c49..b83ef1064fd 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -780,6 +780,8 @@ 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 {
@@ -787,6 +789,8 @@ 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 {
@@ -794,6 +798,8 @@ 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 : Ord {
diff --git a/src/libcore/task.rs b/src/libcore/task.rs
index 04197506d5d..f4514ecd367 100644
--- a/src/libcore/task.rs
+++ b/src/libcore/task.rs
@@ -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) }
 }
 
 /**
@@ -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
@@ -131,6 +131,7 @@ impl Notification : cmp::Eq {
             }
         }
     }
+    pure fn ne(&&other: Notification) -> bool { !self.eq(other) }
 }
 
 /// Scheduler modes
@@ -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
diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs
index 92a0f681a56..2ab8af78b8a 100644
--- a/src/libcore/tuple.rs
+++ b/src/libcore/tuple.rs
@@ -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 {
@@ -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 {
diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs
index c54c8a8c5eb..01668edf3b6 100644
--- a/src/libcore/uint-template.rs
+++ b/src/libcore/uint-template.rs
@@ -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 {
diff --git a/src/libcore/uniq.rs b/src/libcore/uniq.rs
index 8cdacba0286..7a9aa71d199 100644
--- a/src/libcore/uniq.rs
+++ b/src/libcore/uniq.rs
@@ -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 {
diff --git a/src/libcore/unit.rs b/src/libcore/unit.rs
index e4ca11bbd8a..2b09425f752 100644
--- a/src/libcore/unit.rs
+++ b/src/libcore/unit.rs
@@ -6,6 +6,7 @@ use cmp::{Eq, Ord};
 
 impl () : Eq {
     pure fn eq(&&_other: ()) -> bool { true }
+    pure fn ne(&&_other: ()) -> bool { false }
 }
 
 impl () : Ord {
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index 85aebc9ee90..4dedde8e177 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -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