diff options
| author | bors <bors@rust-lang.org> | 2013-03-26 17:54:53 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-03-26 17:54:53 -0700 |
| commit | 5011d05db25fd3dfc0a9dc41fd914633ffb85469 (patch) | |
| tree | 8587ee9f671fc80457df1c6a5417b6d65c0f893e | |
| parent | fa82b9af2ae1f5a32a6f0d34366f0a26aee151d6 (diff) | |
| parent | 3ba7e041f10f1e955120c33f5aab0817e02c5222 (diff) | |
auto merge of #5547 : catamorphism/rust/issue-4898, r=catamorphism
| -rw-r--r-- | src/libcore/repr.rs | 5 | ||||
| -rw-r--r-- | src/libcore/to_str.rs | 11 | ||||
| -rw-r--r-- | 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 39cc986f772..5277ba32614 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 576f794483d..c942f508be8 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<A:ToStr> ToStr for (A,) { + #[inline(always)] + fn to_str(&self) -> ~str { + match *self { + (ref a,) => { + ~"(" + a.to_str() + ~", " + ~")" + } + } + } +} impl<A:ToStr,B:ToStr> ToStr for (A, B) { #[inline(always)] diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index fc7834a7514..1762c2c6426 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -112,7 +112,45 @@ impl<A:Copy,B:Copy> ExtendedTupleOps<A,B> for (~[A], ~[B]) { } } -// FIXME #4898: impl for one-tuples +#[cfg(notest)] +impl<A:Eq> 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<A:Ord> 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<A:Eq,B:Eq> Eq for (A, B) { |
