Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/libcore/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -591,7 +594,6 @@ fn test_repr() {
fail_unless!(s == e);
}


exact_test(&10, "10");
exact_test(&true, "true");
exact_test(&false, "false");
Expand All @@ -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]),
Expand Down
11 changes: 10 additions & 1 deletion src/libcore/to_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
40 changes: 39 additions & 1 deletion src/libcore/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down