diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-01-25 16:57:39 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-01-29 10:42:45 -0800 |
| commit | eb4d39e1fef918242a5dba2a09d7b9faa437b911 (patch) | |
| tree | 92d923119a6d8f1b16d83c2214e8acf9d0dd25e6 /src/libstd/deque.rs | |
| parent | f1e78c6dd7dc41a9937c466a7af5d0efc779909f (diff) | |
| download | rust-eb4d39e1fef918242a5dba2a09d7b9faa437b911.tar.gz rust-eb4d39e1fef918242a5dba2a09d7b9faa437b911.zip | |
libstd: Remove "dual impls" from the language and enforce coherence rules. r=brson
"Dual impls" are impls that are both type implementations and trait implementations. They can lead to ambiguity and so this patch removes them from the language. This also enforces coherence rules. Without this patch, records can implement traits not defined in the current crate. This patch fixes this, and updates all of rustc to adhere to the new enforcement. Most of this patch is fixing rustc to obey the coherence rules, which involves converting a bunch of records to structs.
Diffstat (limited to 'src/libstd/deque.rs')
| -rw-r--r-- | src/libstd/deque.rs | 58 |
1 files changed, 4 insertions, 54 deletions
diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index b4217dfb39d..2abd59523a1 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -249,69 +249,19 @@ mod tests { assert deq.get(3) == d; } + #[deriving_eq] enum Taggy { One(int), Two(int, int), Three(int, int, int), } + #[deriving_eq] enum Taggypar<T> { Onepar(int), Twopar(int, int), Threepar(int, int, int), } + #[deriving_eq] struct RecCy { x: int, y: int, - t: Taggy, - } - - impl Taggy : Eq { - pure fn eq(&self, other: &Taggy) -> bool { - match (*self) { - One(a1) => match (*other) { - One(b1) => return a1 == b1, - _ => return false - }, - Two(a1, a2) => match (*other) { - Two(b1, b2) => return a1 == b1 && a2 == b2, - _ => return false - }, - Three(a1, a2, a3) => match (*other) { - Three(b1, b2, b3) => return a1 == b1 && a2 == b2 && a3 == b3, - _ => return false - } - } - } - pure fn ne(&self, other: &Taggy) -> bool { !(*self).eq(other) } - } - - impl Taggypar<int> : Eq { - //let eq4: EqFn<Taggypar<int>> = |x,y| taggypareq::<int>(x, y); - pure fn eq(&self, other: &Taggypar<int>) -> bool { - match (*self) { - Onepar::<int>(a1) => match (*other) { - Onepar::<int>(b1) => return a1 == b1, - _ => return false - }, - Twopar::<int>(a1, a2) => match (*other) { - Twopar::<int>(b1, b2) => return a1 == b1 && a2 == b2, - _ => return false - }, - Threepar::<int>(a1, a2, a3) => match (*other) { - Threepar::<int>(b1, b2, b3) => { - return a1 == b1 && a2 == b2 && a3 == b3 - } - _ => return false - } - } - } - pure fn ne(&self, other: &Taggypar<int>) -> bool { - !(*self).eq(other) - } - } - - impl RecCy : Eq { - pure fn eq(&self, other: &RecCy) -> bool { - return (*self).x == (*other).x && (*self).y == (*other).y && - (*self).t == (*other).t; - } - pure fn ne(&self, other: &RecCy) -> bool { !(*self).eq(other) } + t: Taggy } #[test] |
