Skip to content

Commit 6f39eb1

Browse files
committed
Delegate ToStr implementation to Show for tuples
1 parent bf6abf8 commit 6f39eb1

File tree

2 files changed

+7
-48
lines changed

2 files changed

+7
-48
lines changed

src/libstd/to_str.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,6 @@ impl ToStr for () {
4040
fn to_str(&self) -> ~str { ~"()" }
4141
}
4242

43-
impl<A:ToStr> ToStr for (A,) {
44-
#[inline]
45-
fn to_str(&self) -> ~str {
46-
match *self {
47-
(ref a,) => {
48-
format!("({},)", (*a).to_str())
49-
}
50-
}
51-
}
52-
}
53-
5443
impl<A:ToStr+Hash+Eq, B:ToStr> ToStr for HashMap<A, B> {
5544
#[inline]
5645
fn to_str(&self) -> ~str {
@@ -91,36 +80,6 @@ impl<A:ToStr+Hash+Eq> ToStr for HashSet<A> {
9180
}
9281
}
9382
94-
impl<A:ToStr,B:ToStr> ToStr for (A, B) {
95-
#[inline]
96-
fn to_str(&self) -> ~str {
97-
// FIXME(#4653): this causes an llvm assertion
98-
//let &(ref a, ref b) = self;
99-
match *self {
100-
(ref a, ref b) => {
101-
format!("({}, {})", (*a).to_str(), (*b).to_str())
102-
}
103-
}
104-
}
105-
}
106-
107-
impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) {
108-
#[inline]
109-
fn to_str(&self) -> ~str {
110-
// FIXME(#4653): this causes an llvm assertion
111-
//let &(ref a, ref b, ref c) = self;
112-
match *self {
113-
(ref a, ref b, ref c) => {
114-
format!("({}, {}, {})",
115-
(*a).to_str(),
116-
(*b).to_str(),
117-
(*c).to_str()
118-
)
119-
}
120-
}
121-
}
122-
}
123-
12483
impl<'a,A:ToStr> ToStr for &'a [A] {
12584
#[inline]
12685
fn to_str(&self) -> ~str {
@@ -178,13 +137,6 @@ mod tests {
178137
assert_eq!((~"hi").to_str(), ~"hi");
179138
}
180139
181-
#[test]
182-
fn test_tuple_types() {
183-
assert_eq!((1, 2).to_str(), ~"(1, 2)");
184-
assert_eq!((~"a", ~"b", false).to_str(), ~"(a, b, false)");
185-
assert_eq!(((), ((), 100)).to_str(), ~"((), ((), 100))");
186-
}
187-
188140
#[test]
189141
fn test_vectors() {
190142
let x: ~[int] = ~[];

src/libstd/tuple.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use clone::Clone;
1717
#[cfg(not(test))] use default::Default;
1818
use fmt;
1919
use result::{Ok, Err};
20+
use to_str::ToStr;
2021

2122
/// Method extensions to pairs where both types satisfy the `Clone` bound
2223
pub trait CloneableTuple<T, U> {
@@ -179,6 +180,12 @@ macro_rules! tuple_impls {
179180
}
180181
}
181182

183+
impl<$($T: fmt::Show),+> ToStr for ($($T,)+) {
184+
fn to_str(&self) -> ~str {
185+
format!("{}", *self)
186+
}
187+
}
188+
182189
impl<$($T: fmt::Show),+> fmt::Show for ($($T,)+) {
183190
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
184191
write_tuple!(f.buf, $(self.$get_ref_fn()),+)

0 commit comments

Comments
 (0)