1
Fork 0

std: Fix pattern match on reference, address an XXX

This commit is contained in:
Tim Chevalier 2013-01-10 20:09:16 -08:00
parent 30c308b952
commit 3e7da96fd2

View file

@ -926,22 +926,20 @@ pub impl Decoder: serialize::Decoder {
impl Json : Eq { impl Json : Eq {
pure fn eq(&self, other: &Json) -> bool { pure fn eq(&self, other: &Json) -> bool {
// XXX: This is ugly because matching on references is broken, and match (self) {
// we can't match on dereferenced tuples without a copy. &Number(f0) =>
match (*self) { match other { &Number(f1) => f0 == f1, _ => false },
Number(f0) => &String(ref s0) =>
match *other { Number(f1) => f0 == f1, _ => false }, match other { &String(ref s1) => s0 == s1, _ => false },
String(ref s0) => &Boolean(b0) =>
match *other { String(ref s1) => s0 == s1, _ => false }, match other { &Boolean(b1) => b0 == b1, _ => false },
Boolean(b0) => &Null =>
match *other { Boolean(b1) => b0 == b1, _ => false }, match other { &Null => true, _ => false },
Null => &List(ref v0) =>
match *other { Null => true, _ => false }, match other { &List(ref v1) => v0 == v1, _ => false },
List(ref v0) => &Object(ref d0) => {
match *other { List(ref v1) => v0 == v1, _ => false }, match other {
Object(ref d0) => { &Object(ref d1) => {
match *other {
Object(ref d1) => {
if d0.len() == d1.len() { if d0.len() == d1.len() {
let mut equal = true; let mut equal = true;
for d0.each |k, v0| { for d0.each |k, v0| {
@ -960,7 +958,7 @@ impl Json : Eq {
} }
} }
} }
pure fn ne(&self, other: &Json) -> bool { !(*self).eq(other) } pure fn ne(&self, other: &Json) -> bool { !self.eq(other) }
} }
/// Test if two json values are less than one another /// Test if two json values are less than one another
@ -1007,7 +1005,7 @@ impl Json : Ord {
let mut d0_flat = ~[]; let mut d0_flat = ~[];
let mut d1_flat = ~[]; let mut d1_flat = ~[];
// XXX: this is horribly inefficient... // FIXME #4430: this is horribly inefficient...
for d0.each |k, v| { for d0.each |k, v| {
d0_flat.push((@copy *k, @copy *v)); d0_flat.push((@copy *k, @copy *v));
} }