From 3ba7e041f10f1e955120c33f5aab0817e02c5222 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 26 Mar 2013 16:08:05 -0700 Subject: [PATCH] core: As per #4898, finish impls for one-tuples --- src/libcore/repr.rs | 5 ++++- src/libcore/to_str.rs | 11 ++++++++++- src/libcore/tuple.rs | 40 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index 39cc986f77252..5277ba32614a3 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -451,6 +451,9 @@ impl TyVisitor for ReprVisitor { } fn visit_leave_tup(&self, _n_fields: uint, _sz: uint, _align: uint) -> bool { + if _n_fields == 1 { + self.writer.write_char(','); + } self.writer.write_char(')'); true } @@ -591,7 +594,6 @@ fn test_repr() { fail_unless!(s == e); } - exact_test(&10, "10"); exact_test(&true, "true"); exact_test(&false, "false"); @@ -608,6 +610,7 @@ fn test_repr() { let mut x = 10; exact_test(&(&mut x), "&mut 10"); + exact_test(&(1,), "(1,)"); exact_test(&(@[1,2,3,4,5,6,7,8]), "@[1, 2, 3, 4, 5, 6, 7, 8]"); exact_test(&(@[1u8,2u8,3u8,4u8]), diff --git a/src/libcore/to_str.rs b/src/libcore/to_str.rs index 576f794483d20..c942f508be841 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -29,7 +29,16 @@ impl ToStr for () { fn to_str(&self) -> ~str { ~"()" } } -// FIXME #4898: impl for one-tuples +impl ToStr for (A,) { + #[inline(always)] + fn to_str(&self) -> ~str { + match *self { + (ref a,) => { + ~"(" + a.to_str() + ~", " + ~")" + } + } + } +} impl ToStr for (A, B) { #[inline(always)] diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index fc7834a7514ac..1762c2c64262c 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -112,7 +112,45 @@ impl ExtendedTupleOps for (~[A], ~[B]) { } } -// FIXME #4898: impl for one-tuples +#[cfg(notest)] +impl Eq for (A,) { + #[inline(always)] + fn eq(&self, other: &(A,)) -> bool { + match (*self) { + (ref self_a,) => match other { + &(ref other_a,) => { + (*self_a).eq(other_a) + } + } + } + } + #[inline(always)] + fn ne(&self, other: &(A,)) -> bool { !(*self).eq(other) } +} + +#[cfg(notest)] +impl Ord for (A,) { + #[inline(always)] + fn lt(&self, other: &(A,)) -> bool { + match (*self) { + (ref self_a,) => { + match (*other) { + (ref other_a,) => { + if (*self_a).lt(other_a) { return true; } + return false; + } + } + } + } + } + #[inline(always)] + fn le(&self, other: &(A,)) -> bool { !other.lt(&(*self)) } + #[inline(always)] + fn ge(&self, other: &(A,)) -> bool { !self.lt(other) } + #[inline(always)] + fn gt(&self, other: &(A,)) -> bool { other.lt(&(*self)) } +} + #[cfg(notest)] impl Eq for (A, B) {