Skip to content

Commit 5011d05

Browse files
committed
auto merge of #5547 : catamorphism/rust/issue-4898, r=catamorphism
2 parents fa82b9a + 3ba7e04 commit 5011d05

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

src/libcore/repr.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ impl TyVisitor for ReprVisitor {
451451
}
452452
fn visit_leave_tup(&self, _n_fields: uint,
453453
_sz: uint, _align: uint) -> bool {
454+
if _n_fields == 1 {
455+
self.writer.write_char(',');
456+
}
454457
self.writer.write_char(')');
455458
true
456459
}
@@ -591,7 +594,6 @@ fn test_repr() {
591594
fail_unless!(s == e);
592595
}
593596

594-
595597
exact_test(&10, "10");
596598
exact_test(&true, "true");
597599
exact_test(&false, "false");
@@ -608,6 +610,7 @@ fn test_repr() {
608610
let mut x = 10;
609611
exact_test(&(&mut x), "&mut 10");
610612

613+
exact_test(&(1,), "(1,)");
611614
exact_test(&(@[1,2,3,4,5,6,7,8]),
612615
"@[1, 2, 3, 4, 5, 6, 7, 8]");
613616
exact_test(&(@[1u8,2u8,3u8,4u8]),

src/libcore/to_str.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ impl ToStr for () {
2929
fn to_str(&self) -> ~str { ~"()" }
3030
}
3131

32-
// FIXME #4898: impl for one-tuples
32+
impl<A:ToStr> ToStr for (A,) {
33+
#[inline(always)]
34+
fn to_str(&self) -> ~str {
35+
match *self {
36+
(ref a,) => {
37+
~"(" + a.to_str() + ~", " + ~")"
38+
}
39+
}
40+
}
41+
}
3342

3443
impl<A:ToStr,B:ToStr> ToStr for (A, B) {
3544
#[inline(always)]

src/libcore/tuple.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,45 @@ impl<A:Copy,B:Copy> ExtendedTupleOps<A,B> for (~[A], ~[B]) {
112112
}
113113
}
114114

115-
// FIXME #4898: impl for one-tuples
115+
#[cfg(notest)]
116+
impl<A:Eq> Eq for (A,) {
117+
#[inline(always)]
118+
fn eq(&self, other: &(A,)) -> bool {
119+
match (*self) {
120+
(ref self_a,) => match other {
121+
&(ref other_a,) => {
122+
(*self_a).eq(other_a)
123+
}
124+
}
125+
}
126+
}
127+
#[inline(always)]
128+
fn ne(&self, other: &(A,)) -> bool { !(*self).eq(other) }
129+
}
130+
131+
#[cfg(notest)]
132+
impl<A:Ord> Ord for (A,) {
133+
#[inline(always)]
134+
fn lt(&self, other: &(A,)) -> bool {
135+
match (*self) {
136+
(ref self_a,) => {
137+
match (*other) {
138+
(ref other_a,) => {
139+
if (*self_a).lt(other_a) { return true; }
140+
return false;
141+
}
142+
}
143+
}
144+
}
145+
}
146+
#[inline(always)]
147+
fn le(&self, other: &(A,)) -> bool { !other.lt(&(*self)) }
148+
#[inline(always)]
149+
fn ge(&self, other: &(A,)) -> bool { !self.lt(other) }
150+
#[inline(always)]
151+
fn gt(&self, other: &(A,)) -> bool { other.lt(&(*self)) }
152+
}
153+
116154

117155
#[cfg(notest)]
118156
impl<A:Eq,B:Eq> Eq for (A, B) {

0 commit comments

Comments
 (0)