Skip to content

Commit 92095d1

Browse files
committed
core: Inherit the tuple module
1 parent 1a989d6 commit 92095d1

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ pub mod any;
4444
pub mod finally;
4545
pub mod raw;
4646
pub mod char;
47+
pub mod tuple;

src/libstd/tuple.rs renamed to src/libcore/tuple.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
use clone::Clone;
1616
#[cfg(not(test))] use cmp::*;
1717
#[cfg(not(test))] use default::Default;
18-
use fmt;
19-
use result::{Ok, Err};
2018

2119
// macro for implementing n-ary tuple functions and operations
2220
macro_rules! tuple_impls {
@@ -112,12 +110,6 @@ macro_rules! tuple_impls {
112110
($({ let x: $T = Default::default(); x},)+)
113111
}
114112
}
115-
116-
impl<$($T: fmt::Show),+> fmt::Show for ($($T,)+) {
117-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
118-
write_tuple!(f.buf, $(self.$refN()),+)
119-
}
120-
}
121113
)+
122114
}
123115
}
@@ -144,18 +136,6 @@ macro_rules! lexical_cmp {
144136
($a:expr, $b:expr) => { ($a).cmp($b) };
145137
}
146138

147-
macro_rules! write_tuple {
148-
($buf:expr, $x:expr) => (
149-
write!($buf, "({},)", *$x)
150-
);
151-
($buf:expr, $hd:expr, $($tl:expr),+) => ({
152-
try!(write!($buf, "("));
153-
try!(write!($buf, "{}", *$hd));
154-
$(try!(write!($buf, ", {}", *$tl));)+
155-
write!($buf, ")")
156-
});
157-
}
158-
159139
tuple_impls! {
160140
Tuple1 {
161141
(val0, ref0, mut0) -> A { (a) => a }

src/libstd/fmt/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,36 @@ impl<T> Show for *mut T {
12421242
fn fmt(&self, f: &mut Formatter) -> Result { secret_pointer(self, f) }
12431243
}
12441244

1245+
macro_rules! peel(($name:ident, $($other:ident,)*) => (tuple!($($other,)*)))
1246+
1247+
macro_rules! tuple (
1248+
() => ();
1249+
( $($name:ident,)+ ) => (
1250+
impl<$($name:Show),*> Show for ($($name,)*) {
1251+
#[allow(uppercase_variables, dead_assignment)]
1252+
fn fmt(&self, f: &mut Formatter) -> Result {
1253+
try!(write!(f.buf, "("));
1254+
let ($(ref $name,)*) = *self;
1255+
let mut n = 0;
1256+
$(
1257+
if n > 0 {
1258+
try!(write!(f.buf, ", "));
1259+
}
1260+
try!(write!(f.buf, "{}", *$name));
1261+
n += 1;
1262+
)*
1263+
if n == 1 {
1264+
try!(write!(f.buf, ","));
1265+
}
1266+
write!(f.buf, ")")
1267+
}
1268+
}
1269+
peel!($($name,)*)
1270+
)
1271+
)
1272+
1273+
tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
1274+
12451275
impl Show for Box<any::Any> {
12461276
fn fmt(&self, f: &mut Formatter) -> Result { f.pad("Box<Any>") }
12471277
}

src/libstd/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ pub use core::intrinsics;
147147
pub use core::mem;
148148
pub use core::ptr;
149149
pub use core::raw;
150+
pub use core::tuple;
150151

151152
// Run tests with libgreen instead of libnative.
152153
//
@@ -192,7 +193,6 @@ pub mod prelude;
192193
#[path = "num/f64.rs"] pub mod f64;
193194

194195
pub mod bool;
195-
pub mod tuple;
196196

197197
pub mod slice;
198198
pub mod vec;

0 commit comments

Comments
 (0)