From bf6abf8cb3d1e169c1baab8d266bd43c58dfbcc6 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sat, 15 Feb 2014 01:20:43 +1100 Subject: Implement Show for 1-12 element tuples --- src/libstd/tuple.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 33d23df242c..9a1fda07ecd 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -15,6 +15,8 @@ use clone::Clone; #[cfg(not(test))] use cmp::*; #[cfg(not(test))] use default::Default; +use fmt; +use result::{Ok, Err}; /// Method extensions to pairs where both types satisfy the `Clone` bound pub trait CloneableTuple { @@ -176,6 +178,12 @@ macro_rules! tuple_impls { ($({ let x: $T = Default::default(); x},)+) } } + + impl<$($T: fmt::Show),+> fmt::Show for ($($T,)+) { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write_tuple!(f.buf, $(self.$get_ref_fn()),+) + } + } )+ } } @@ -202,6 +210,17 @@ macro_rules! lexical_cmp { ($a:expr, $b:expr) => { ($a).cmp($b) }; } +macro_rules! write_tuple { + ($buf:expr, $x:expr) => ( + write!($buf, "({},)", *$x) + ); + ($buf:expr, $hd:expr, $($tl:expr),+) => ({ + if_ok!(write!($buf, "(")); + if_ok!(write!($buf, "{}", *$hd)); + $(if_ok!(write!($buf, ", {}", *$tl));)+ + write!($buf, ")") + }); +} tuple_impls! { (Tuple1, ImmutableTuple1) { @@ -422,4 +441,11 @@ mod tests { assert_eq!(small.cmp(&big), Less); assert_eq!(big.cmp(&small), Greater); } + + #[test] + fn test_show() { + assert_eq!(format!("{}", (1,)), ~"(1,)"); + assert_eq!(format!("{}", (1, true)), ~"(1, true)"); + assert_eq!(format!("{}", (1, ~"hi", true)), ~"(1, hi, true)"); + } } -- cgit 1.4.1-3-g733a5 From 6f39eb1a568c03534a41f6815e7fb0bde737cd6f Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 16 Feb 2014 18:27:46 +1100 Subject: Delegate ToStr implementation to Show for tuples --- src/libstd/to_str.rs | 48 ------------------------------------------------ src/libstd/tuple.rs | 7 +++++++ 2 files changed, 7 insertions(+), 48 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index 87d59f09791..ab14e9f5667 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -40,17 +40,6 @@ impl ToStr for () { fn to_str(&self) -> ~str { ~"()" } } -impl ToStr for (A,) { - #[inline] - fn to_str(&self) -> ~str { - match *self { - (ref a,) => { - format!("({},)", (*a).to_str()) - } - } - } -} - impl ToStr for HashMap { #[inline] fn to_str(&self) -> ~str { @@ -91,36 +80,6 @@ impl ToStr for HashSet { } } -impl ToStr for (A, B) { - #[inline] - fn to_str(&self) -> ~str { - // FIXME(#4653): this causes an llvm assertion - //let &(ref a, ref b) = self; - match *self { - (ref a, ref b) => { - format!("({}, {})", (*a).to_str(), (*b).to_str()) - } - } - } -} - -impl ToStr for (A, B, C) { - #[inline] - fn to_str(&self) -> ~str { - // FIXME(#4653): this causes an llvm assertion - //let &(ref a, ref b, ref c) = self; - match *self { - (ref a, ref b, ref c) => { - format!("({}, {}, {})", - (*a).to_str(), - (*b).to_str(), - (*c).to_str() - ) - } - } - } -} - impl<'a,A:ToStr> ToStr for &'a [A] { #[inline] fn to_str(&self) -> ~str { @@ -178,13 +137,6 @@ mod tests { assert_eq!((~"hi").to_str(), ~"hi"); } - #[test] - fn test_tuple_types() { - assert_eq!((1, 2).to_str(), ~"(1, 2)"); - assert_eq!((~"a", ~"b", false).to_str(), ~"(a, b, false)"); - assert_eq!(((), ((), 100)).to_str(), ~"((), ((), 100))"); - } - #[test] fn test_vectors() { let x: ~[int] = ~[]; diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 9a1fda07ecd..f2d1144f281 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -17,6 +17,7 @@ use clone::Clone; #[cfg(not(test))] use default::Default; use fmt; use result::{Ok, Err}; +use to_str::ToStr; /// Method extensions to pairs where both types satisfy the `Clone` bound pub trait CloneableTuple { @@ -179,6 +180,12 @@ macro_rules! tuple_impls { } } + impl<$($T: fmt::Show),+> ToStr for ($($T,)+) { + fn to_str(&self) -> ~str { + format!("{}", *self) + } + } + impl<$($T: fmt::Show),+> fmt::Show for ($($T,)+) { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write_tuple!(f.buf, $(self.$get_ref_fn()),+) -- cgit 1.4.1-3-g733a5 From 2cd7a290133f2ec7941215539dfc549f778f7be5 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 16 Feb 2014 20:25:28 +1100 Subject: Merge ImmutableTuple* traits into their respective Tuple* trait --- src/libstd/prelude.rs | 3 --- src/libstd/tuple.rs | 51 ++++++++++++++++----------------------------------- 2 files changed, 16 insertions(+), 38 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 3eaa1db87ba..ef159d68df7 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -68,9 +68,6 @@ pub use str::{Str, StrVector, StrSlice, OwnedStr, IntoMaybeOwned}; pub use to_bytes::IterBytes; pub use to_str::{ToStr, IntoStr}; pub use tuple::{CloneableTuple, ImmutableTuple}; -pub use tuple::{ImmutableTuple1, ImmutableTuple2, ImmutableTuple3, ImmutableTuple4}; -pub use tuple::{ImmutableTuple5, ImmutableTuple6, ImmutableTuple7, ImmutableTuple8}; -pub use tuple::{ImmutableTuple9, ImmutableTuple10, ImmutableTuple11, ImmutableTuple12}; pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4}; pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8}; pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12}; diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index f2d1144f281..18014fc17f9 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -80,36 +80,28 @@ impl ImmutableTuple for (T, U) { } // macro for implementing n-ary tuple functions and operations - macro_rules! tuple_impls { ($( - ($move_trait:ident, $immutable_trait:ident) { + $Tuple:ident { $(($get_fn:ident, $get_ref_fn:ident) -> $T:ident { $move_pattern:pat, $ref_pattern:pat => $ret:expr })+ } )+) => { $( - pub trait $move_trait<$($T),+> { + pub trait $Tuple<$($T),+> { $(fn $get_fn(self) -> $T;)+ + $(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+ } - impl<$($T),+> $move_trait<$($T),+> for ($($T,)+) { + impl<$($T),+> $Tuple<$($T),+> for ($($T,)+) { $( #[inline] fn $get_fn(self) -> $T { let $move_pattern = self; $ret } - )+ - } - - pub trait $immutable_trait<$($T),+> { - $(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+ - } - impl<$($T),+> $immutable_trait<$($T),+> for ($($T,)+) { - $( #[inline] fn $get_ref_fn<'a>(&'a self) -> &'a $T { let $ref_pattern = *self; @@ -230,37 +222,32 @@ macro_rules! write_tuple { } tuple_impls! { - (Tuple1, ImmutableTuple1) { + Tuple1 { (n0, n0_ref) -> A { (a,), (ref a,) => a } } - - (Tuple2, ImmutableTuple2) { + Tuple2 { (n0, n0_ref) -> A { (a,_), (ref a,_) => a } (n1, n1_ref) -> B { (_,b), (_,ref b) => b } } - - (Tuple3, ImmutableTuple3) { + Tuple3 { (n0, n0_ref) -> A { (a,_,_), (ref a,_,_) => a } (n1, n1_ref) -> B { (_,b,_), (_,ref b,_) => b } (n2, n2_ref) -> C { (_,_,c), (_,_,ref c) => c } } - - (Tuple4, ImmutableTuple4) { + Tuple4 { (n0, n0_ref) -> A { (a,_,_,_), (ref a,_,_,_) => a } (n1, n1_ref) -> B { (_,b,_,_), (_,ref b,_,_) => b } (n2, n2_ref) -> C { (_,_,c,_), (_,_,ref c,_) => c } (n3, n3_ref) -> D { (_,_,_,d), (_,_,_,ref d) => d } } - - (Tuple5, ImmutableTuple5) { + Tuple5 { (n0, n0_ref) -> A { (a,_,_,_,_), (ref a,_,_,_,_) => a } (n1, n1_ref) -> B { (_,b,_,_,_), (_,ref b,_,_,_) => b } (n2, n2_ref) -> C { (_,_,c,_,_), (_,_,ref c,_,_) => c } (n3, n3_ref) -> D { (_,_,_,d,_), (_,_,_,ref d,_) => d } (n4, n4_ref) -> E { (_,_,_,_,e), (_,_,_,_,ref e) => e } } - - (Tuple6, ImmutableTuple6) { + Tuple6 { (n0, n0_ref) -> A { (a,_,_,_,_,_), (ref a,_,_,_,_,_) => a } (n1, n1_ref) -> B { (_,b,_,_,_,_), (_,ref b,_,_,_,_) => b } (n2, n2_ref) -> C { (_,_,c,_,_,_), (_,_,ref c,_,_,_) => c } @@ -268,8 +255,7 @@ tuple_impls! { (n4, n4_ref) -> E { (_,_,_,_,e,_), (_,_,_,_,ref e,_) => e } (n5, n5_ref) -> F { (_,_,_,_,_,f), (_,_,_,_,_,ref f) => f } } - - (Tuple7, ImmutableTuple7) { + Tuple7 { (n0, n0_ref) -> A { (a,_,_,_,_,_,_), (ref a,_,_,_,_,_,_) => a } (n1, n1_ref) -> B { (_,b,_,_,_,_,_), (_,ref b,_,_,_,_,_) => b } (n2, n2_ref) -> C { (_,_,c,_,_,_,_), (_,_,ref c,_,_,_,_) => c } @@ -278,8 +264,7 @@ tuple_impls! { (n5, n5_ref) -> F { (_,_,_,_,_,f,_), (_,_,_,_,_,ref f,_) => f } (n6, n6_ref) -> G { (_,_,_,_,_,_,g), (_,_,_,_,_,_,ref g) => g } } - - (Tuple8, ImmutableTuple8) { + Tuple8 { (n0, n0_ref) -> A { (a,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_) => a } (n1, n1_ref) -> B { (_,b,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_) => b } (n2, n2_ref) -> C { (_,_,c,_,_,_,_,_), (_,_,ref c,_,_,_,_,_) => c } @@ -289,8 +274,7 @@ tuple_impls! { (n6, n6_ref) -> G { (_,_,_,_,_,_,g,_), (_,_,_,_,_,_,ref g,_) => g } (n7, n7_ref) -> H { (_,_,_,_,_,_,_,h), (_,_,_,_,_,_,_,ref h) => h } } - - (Tuple9, ImmutableTuple9) { + Tuple9 { (n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_) => a } (n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_) => b } (n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_) => c } @@ -301,8 +285,7 @@ tuple_impls! { (n7, n7_ref) -> H { (_,_,_,_,_,_,_,h,_), (_,_,_,_,_,_,_,ref h,_) => h } (n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i), (_,_,_,_,_,_,_,_,ref i) => i } } - - (Tuple10, ImmutableTuple10) { + Tuple10 { (n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_) => a } (n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_) => b } (n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_) => c } @@ -314,8 +297,7 @@ tuple_impls! { (n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i,_), (_,_,_,_,_,_,_,_,ref i,_) => i } (n9, n9_ref) -> J { (_,_,_,_,_,_,_,_,_,j), (_,_,_,_,_,_,_,_,_,ref j) => j } } - - (Tuple11, ImmutableTuple11) { + Tuple11 { (n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_,_) => a } (n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_,_) => b } (n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_,_) => c } @@ -328,8 +310,7 @@ tuple_impls! { (n9, n9_ref) -> J { (_,_,_,_,_,_,_,_,_,j,_), (_,_,_,_,_,_,_,_,_,ref j,_) => j } (n10, n10_ref) -> K { (_,_,_,_,_,_,_,_,_,_,k), (_,_,_,_,_,_,_,_,_,_,ref k) => k } } - - (Tuple12, ImmutableTuple12) { + Tuple12 { (n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_,_,_) => a } (n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_,_,_) => b } (n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_,_,_) => c } -- cgit 1.4.1-3-g733a5 From cf0654c47c0d47478cdafec89ae250a86b4f2c17 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 16 Feb 2014 22:19:41 +1100 Subject: Improve naming of tuple getters, and add mutable tuple getter Renames the `n*` and `n*_ref` tuple getters to `val*` and `ref*` respectively, and adds `mut*` getters. --- src/libcollections/btree.rs | 8 +- src/librustdoc/html/render.rs | 4 +- src/librustdoc/lib.rs | 2 +- src/libstd/tuple.rs | 253 ++++++++++++++++++++------------------- src/test/bench/shootout-fasta.rs | 2 +- 5 files changed, 136 insertions(+), 133 deletions(-) (limited to 'src/libstd') diff --git a/src/libcollections/btree.rs b/src/libcollections/btree.rs index 34aee6459a8..13b39da0756 100644 --- a/src/libcollections/btree.rs +++ b/src/libcollections/btree.rs @@ -500,15 +500,15 @@ impl Branch { let new_outcome = self.clone().rightmost_child.insert(k.clone(), v.clone(), ub.clone()); - new_branch = new_outcome.clone().n0(); - outcome = new_outcome.n1(); + new_branch = new_outcome.clone().val0(); + outcome = new_outcome.val1(); } else { let new_outcome = self.clone().elts[index.unwrap()].left.insert(k.clone(), v.clone(), ub.clone()); - new_branch = new_outcome.clone().n0(); - outcome = new_outcome.n1(); + new_branch = new_outcome.clone().val0(); + outcome = new_outcome.val1(); } //Check to see whether a branch or a leaf was returned from the //tree traversal. diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index c7c4aae35e3..11f80155085 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1379,11 +1379,11 @@ fn render_methods(w: &mut Writer, it: &clean::Item) -> fmt::Result { match c.impls.find(&it.id) { Some(v) => { let mut non_trait = v.iter().filter(|p| { - p.n0_ref().trait_.is_none() + p.ref0().trait_.is_none() }); let non_trait = non_trait.to_owned_vec(); let mut traits = v.iter().filter(|p| { - p.n0_ref().trait_.is_some() + p.ref0().trait_.is_some() }); let traits = traits.to_owned_vec(); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index e9072fb37bb..24c9d81e530 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -262,7 +262,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output { let mut pm = plugins::PluginManager::new(Path::new(path)); for pass in passes.iter() { let plugin = match PASSES.iter().position(|&(p, _, _)| p == *pass) { - Some(i) => PASSES[i].n1(), + Some(i) => PASSES[i].val1(), None => { error!("unknown pass {}, skipping", *pass); continue diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 18014fc17f9..91625a53c94 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -83,36 +83,43 @@ impl ImmutableTuple for (T, U) { macro_rules! tuple_impls { ($( $Tuple:ident { - $(($get_fn:ident, $get_ref_fn:ident) -> $T:ident { - $move_pattern:pat, $ref_pattern:pat => $ret:expr + $(($valN:ident, $refN:ident, $mutN:ident) -> $T:ident { + ($($x:ident),+) => $ret:expr })+ } )+) => { $( pub trait $Tuple<$($T),+> { - $(fn $get_fn(self) -> $T;)+ - $(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+ + $(fn $valN(self) -> $T;)+ + $(fn $refN<'a>(&'a self) -> &'a $T;)+ + $(fn $mutN<'a>(&'a mut self) -> &'a mut $T;)+ } impl<$($T),+> $Tuple<$($T),+> for ($($T,)+) { $( #[inline] - fn $get_fn(self) -> $T { - let $move_pattern = self; - $ret + #[allow(unused_variable)] + fn $valN(self) -> $T { + let ($($x,)+) = self; $ret } #[inline] - fn $get_ref_fn<'a>(&'a self) -> &'a $T { - let $ref_pattern = *self; - $ret + #[allow(unused_variable)] + fn $refN<'a>(&'a self) -> &'a $T { + let ($(ref $x,)+) = *self; $ret + } + + #[inline] + #[allow(unused_variable)] + fn $mutN<'a>(&'a mut self) -> &'a mut $T { + let ($(ref mut $x,)+) = *self; $ret } )+ } impl<$($T:Clone),+> Clone for ($($T,)+) { fn clone(&self) -> ($($T,)+) { - ($(self.$get_ref_fn().clone(),)+) + ($(self.$refN().clone(),)+) } } @@ -120,11 +127,11 @@ macro_rules! tuple_impls { impl<$($T:Eq),+> Eq for ($($T,)+) { #[inline] fn eq(&self, other: &($($T,)+)) -> bool { - $(*self.$get_ref_fn() == *other.$get_ref_fn())&&+ + $(*self.$refN() == *other.$refN())&&+ } #[inline] fn ne(&self, other: &($($T,)+)) -> bool { - $(*self.$get_ref_fn() != *other.$get_ref_fn())||+ + $(*self.$refN() != *other.$refN())||+ } } @@ -132,7 +139,7 @@ macro_rules! tuple_impls { impl<$($T:TotalEq),+> TotalEq for ($($T,)+) { #[inline] fn equals(&self, other: &($($T,)+)) -> bool { - $(self.$get_ref_fn().equals(other.$get_ref_fn()))&&+ + $(self.$refN().equals(other.$refN()))&&+ } } @@ -140,19 +147,19 @@ macro_rules! tuple_impls { impl<$($T:Ord + Eq),+> Ord for ($($T,)+) { #[inline] fn lt(&self, other: &($($T,)+)) -> bool { - lexical_ord!(lt, $(self.$get_ref_fn(), other.$get_ref_fn()),+) + lexical_ord!(lt, $(self.$refN(), other.$refN()),+) } #[inline] fn le(&self, other: &($($T,)+)) -> bool { - lexical_ord!(le, $(self.$get_ref_fn(), other.$get_ref_fn()),+) + lexical_ord!(le, $(self.$refN(), other.$refN()),+) } #[inline] fn ge(&self, other: &($($T,)+)) -> bool { - lexical_ord!(ge, $(self.$get_ref_fn(), other.$get_ref_fn()),+) + lexical_ord!(ge, $(self.$refN(), other.$refN()),+) } #[inline] fn gt(&self, other: &($($T,)+)) -> bool { - lexical_ord!(gt, $(self.$get_ref_fn(), other.$get_ref_fn()),+) + lexical_ord!(gt, $(self.$refN(), other.$refN()),+) } } @@ -160,7 +167,7 @@ macro_rules! tuple_impls { impl<$($T:TotalOrd),+> TotalOrd for ($($T,)+) { #[inline] fn cmp(&self, other: &($($T,)+)) -> Ordering { - lexical_cmp!($(self.$get_ref_fn(), other.$get_ref_fn()),+) + lexical_cmp!($(self.$refN(), other.$refN()),+) } } @@ -180,7 +187,7 @@ macro_rules! tuple_impls { impl<$($T: fmt::Show),+> fmt::Show for ($($T,)+) { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write_tuple!(f.buf, $(self.$get_ref_fn()),+) + write_tuple!(f.buf, $(self.$refN()),+) } } )+ @@ -223,106 +230,106 @@ macro_rules! write_tuple { tuple_impls! { Tuple1 { - (n0, n0_ref) -> A { (a,), (ref a,) => a } + (val0, ref0, mut0) -> A { (a) => a } } Tuple2 { - (n0, n0_ref) -> A { (a,_), (ref a,_) => a } - (n1, n1_ref) -> B { (_,b), (_,ref b) => b } + (val0, ref0, mut0) -> A { (a, b) => a } + (val1, ref1, mut1) -> B { (a, b) => b } } Tuple3 { - (n0, n0_ref) -> A { (a,_,_), (ref a,_,_) => a } - (n1, n1_ref) -> B { (_,b,_), (_,ref b,_) => b } - (n2, n2_ref) -> C { (_,_,c), (_,_,ref c) => c } + (val0, ref0, mut0) -> A { (a, b, c) => a } + (val1, ref1, mut1) -> B { (a, b, c) => b } + (val2, ref2, mut2) -> C { (a, b, c) => c } } Tuple4 { - (n0, n0_ref) -> A { (a,_,_,_), (ref a,_,_,_) => a } - (n1, n1_ref) -> B { (_,b,_,_), (_,ref b,_,_) => b } - (n2, n2_ref) -> C { (_,_,c,_), (_,_,ref c,_) => c } - (n3, n3_ref) -> D { (_,_,_,d), (_,_,_,ref d) => d } + (val0, ref0, mut0) -> A { (a, b, c, d) => a } + (val1, ref1, mut1) -> B { (a, b, c, d) => b } + (val2, ref2, mut2) -> C { (a, b, c, d) => c } + (val3, ref3, mut3) -> D { (a, b, c, d) => d } } Tuple5 { - (n0, n0_ref) -> A { (a,_,_,_,_), (ref a,_,_,_,_) => a } - (n1, n1_ref) -> B { (_,b,_,_,_), (_,ref b,_,_,_) => b } - (n2, n2_ref) -> C { (_,_,c,_,_), (_,_,ref c,_,_) => c } - (n3, n3_ref) -> D { (_,_,_,d,_), (_,_,_,ref d,_) => d } - (n4, n4_ref) -> E { (_,_,_,_,e), (_,_,_,_,ref e) => e } + (val0, ref0, mut0) -> A { (a, b, c, d, e) => a } + (val1, ref1, mut1) -> B { (a, b, c, d, e) => b } + (val2, ref2, mut2) -> C { (a, b, c, d, e) => c } + (val3, ref3, mut3) -> D { (a, b, c, d, e) => d } + (val4, ref4, mut4) -> E { (a, b, c, d, e) => e } } Tuple6 { - (n0, n0_ref) -> A { (a,_,_,_,_,_), (ref a,_,_,_,_,_) => a } - (n1, n1_ref) -> B { (_,b,_,_,_,_), (_,ref b,_,_,_,_) => b } - (n2, n2_ref) -> C { (_,_,c,_,_,_), (_,_,ref c,_,_,_) => c } - (n3, n3_ref) -> D { (_,_,_,d,_,_), (_,_,_,ref d,_,_) => d } - (n4, n4_ref) -> E { (_,_,_,_,e,_), (_,_,_,_,ref e,_) => e } - (n5, n5_ref) -> F { (_,_,_,_,_,f), (_,_,_,_,_,ref f) => f } + (val0, ref0, mut0) -> A { (a, b, c, d, e, f) => a } + (val1, ref1, mut1) -> B { (a, b, c, d, e, f) => b } + (val2, ref2, mut2) -> C { (a, b, c, d, e, f) => c } + (val3, ref3, mut3) -> D { (a, b, c, d, e, f) => d } + (val4, ref4, mut4) -> E { (a, b, c, d, e, f) => e } + (val5, ref5, mut5) -> F { (a, b, c, d, e, f) => f } } Tuple7 { - (n0, n0_ref) -> A { (a,_,_,_,_,_,_), (ref a,_,_,_,_,_,_) => a } - (n1, n1_ref) -> B { (_,b,_,_,_,_,_), (_,ref b,_,_,_,_,_) => b } - (n2, n2_ref) -> C { (_,_,c,_,_,_,_), (_,_,ref c,_,_,_,_) => c } - (n3, n3_ref) -> D { (_,_,_,d,_,_,_), (_,_,_,ref d,_,_,_) => d } - (n4, n4_ref) -> E { (_,_,_,_,e,_,_), (_,_,_,_,ref e,_,_) => e } - (n5, n5_ref) -> F { (_,_,_,_,_,f,_), (_,_,_,_,_,ref f,_) => f } - (n6, n6_ref) -> G { (_,_,_,_,_,_,g), (_,_,_,_,_,_,ref g) => g } + (val0, ref0, mut0) -> A { (a, b, c, d, e, f, g) => a } + (val1, ref1, mut1) -> B { (a, b, c, d, e, f, g) => b } + (val2, ref2, mut2) -> C { (a, b, c, d, e, f, g) => c } + (val3, ref3, mut3) -> D { (a, b, c, d, e, f, g) => d } + (val4, ref4, mut4) -> E { (a, b, c, d, e, f, g) => e } + (val5, ref5, mut5) -> F { (a, b, c, d, e, f, g) => f } + (val6, ref6, mut6) -> G { (a, b, c, d, e, f, g) => g } } Tuple8 { - (n0, n0_ref) -> A { (a,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_) => a } - (n1, n1_ref) -> B { (_,b,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_) => b } - (n2, n2_ref) -> C { (_,_,c,_,_,_,_,_), (_,_,ref c,_,_,_,_,_) => c } - (n3, n3_ref) -> D { (_,_,_,d,_,_,_,_), (_,_,_,ref d,_,_,_,_) => d } - (n4, n4_ref) -> E { (_,_,_,_,e,_,_,_), (_,_,_,_,ref e,_,_,_) => e } - (n5, n5_ref) -> F { (_,_,_,_,_,f,_,_), (_,_,_,_,_,ref f,_,_) => f } - (n6, n6_ref) -> G { (_,_,_,_,_,_,g,_), (_,_,_,_,_,_,ref g,_) => g } - (n7, n7_ref) -> H { (_,_,_,_,_,_,_,h), (_,_,_,_,_,_,_,ref h) => h } + (val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h) => a } + (val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h) => b } + (val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h) => c } + (val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h) => d } + (val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h) => e } + (val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h) => f } + (val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h) => g } + (val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h) => h } } Tuple9 { - (n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_) => a } - (n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_) => b } - (n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_) => c } - (n3, n3_ref) -> D { (_,_,_,d,_,_,_,_,_), (_,_,_,ref d,_,_,_,_,_) => d } - (n4, n4_ref) -> E { (_,_,_,_,e,_,_,_,_), (_,_,_,_,ref e,_,_,_,_) => e } - (n5, n5_ref) -> F { (_,_,_,_,_,f,_,_,_), (_,_,_,_,_,ref f,_,_,_) => f } - (n6, n6_ref) -> G { (_,_,_,_,_,_,g,_,_), (_,_,_,_,_,_,ref g,_,_) => g } - (n7, n7_ref) -> H { (_,_,_,_,_,_,_,h,_), (_,_,_,_,_,_,_,ref h,_) => h } - (n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i), (_,_,_,_,_,_,_,_,ref i) => i } + (val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h, i) => a } + (val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h, i) => b } + (val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h, i) => c } + (val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h, i) => d } + (val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h, i) => e } + (val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h, i) => f } + (val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h, i) => g } + (val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h, i) => h } + (val8, ref8, mut8) -> I { (a, b, c, d, e, f, g, h, i) => i } } Tuple10 { - (n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_) => a } - (n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_) => b } - (n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_) => c } - (n3, n3_ref) -> D { (_,_,_,d,_,_,_,_,_,_), (_,_,_,ref d,_,_,_,_,_,_) => d } - (n4, n4_ref) -> E { (_,_,_,_,e,_,_,_,_,_), (_,_,_,_,ref e,_,_,_,_,_) => e } - (n5, n5_ref) -> F { (_,_,_,_,_,f,_,_,_,_), (_,_,_,_,_,ref f,_,_,_,_) => f } - (n6, n6_ref) -> G { (_,_,_,_,_,_,g,_,_,_), (_,_,_,_,_,_,ref g,_,_,_) => g } - (n7, n7_ref) -> H { (_,_,_,_,_,_,_,h,_,_), (_,_,_,_,_,_,_,ref h,_,_) => h } - (n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i,_), (_,_,_,_,_,_,_,_,ref i,_) => i } - (n9, n9_ref) -> J { (_,_,_,_,_,_,_,_,_,j), (_,_,_,_,_,_,_,_,_,ref j) => j } + (val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h, i, j) => a } + (val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h, i, j) => b } + (val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h, i, j) => c } + (val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h, i, j) => d } + (val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h, i, j) => e } + (val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h, i, j) => f } + (val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h, i, j) => g } + (val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h, i, j) => h } + (val8, ref8, mut8) -> I { (a, b, c, d, e, f, g, h, i, j) => i } + (val9, ref9, mut9) -> J { (a, b, c, d, e, f, g, h, i, j) => j } } Tuple11 { - (n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_,_) => a } - (n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_,_) => b } - (n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_,_) => c } - (n3, n3_ref) -> D { (_,_,_,d,_,_,_,_,_,_,_), (_,_,_,ref d,_,_,_,_,_,_,_) => d } - (n4, n4_ref) -> E { (_,_,_,_,e,_,_,_,_,_,_), (_,_,_,_,ref e,_,_,_,_,_,_) => e } - (n5, n5_ref) -> F { (_,_,_,_,_,f,_,_,_,_,_), (_,_,_,_,_,ref f,_,_,_,_,_) => f } - (n6, n6_ref) -> G { (_,_,_,_,_,_,g,_,_,_,_), (_,_,_,_,_,_,ref g,_,_,_,_) => g } - (n7, n7_ref) -> H { (_,_,_,_,_,_,_,h,_,_,_), (_,_,_,_,_,_,_,ref h,_,_,_) => h } - (n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i,_,_), (_,_,_,_,_,_,_,_,ref i,_,_) => i } - (n9, n9_ref) -> J { (_,_,_,_,_,_,_,_,_,j,_), (_,_,_,_,_,_,_,_,_,ref j,_) => j } - (n10, n10_ref) -> K { (_,_,_,_,_,_,_,_,_,_,k), (_,_,_,_,_,_,_,_,_,_,ref k) => k } + (val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h, i, j, k) => a } + (val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h, i, j, k) => b } + (val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h, i, j, k) => c } + (val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h, i, j, k) => d } + (val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h, i, j, k) => e } + (val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h, i, j, k) => f } + (val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h, i, j, k) => g } + (val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h, i, j, k) => h } + (val8, ref8, mut8) -> I { (a, b, c, d, e, f, g, h, i, j, k) => i } + (val9, ref9, mut9) -> J { (a, b, c, d, e, f, g, h, i, j, k) => j } + (val10, ref10, mut10) -> K { (a, b, c, d, e, f, g, h, i, j, k) => k } } Tuple12 { - (n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_,_,_) => a } - (n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_,_,_) => b } - (n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_,_,_) => c } - (n3, n3_ref) -> D { (_,_,_,d,_,_,_,_,_,_,_,_), (_,_,_,ref d,_,_,_,_,_,_,_,_) => d } - (n4, n4_ref) -> E { (_,_,_,_,e,_,_,_,_,_,_,_), (_,_,_,_,ref e,_,_,_,_,_,_,_) => e } - (n5, n5_ref) -> F { (_,_,_,_,_,f,_,_,_,_,_,_), (_,_,_,_,_,ref f,_,_,_,_,_,_) => f } - (n6, n6_ref) -> G { (_,_,_,_,_,_,g,_,_,_,_,_), (_,_,_,_,_,_,ref g,_,_,_,_,_) => g } - (n7, n7_ref) -> H { (_,_,_,_,_,_,_,h,_,_,_,_), (_,_,_,_,_,_,_,ref h,_,_,_,_) => h } - (n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i,_,_,_), (_,_,_,_,_,_,_,_,ref i,_,_,_) => i } - (n9, n9_ref) -> J { (_,_,_,_,_,_,_,_,_,j,_,_), (_,_,_,_,_,_,_,_,_,ref j,_,_) => j } - (n10, n10_ref) -> K { (_,_,_,_,_,_,_,_,_,_,k,_), (_,_,_,_,_,_,_,_,_,_,ref k,_) => k } - (n11, n11_ref) -> L { (_,_,_,_,_,_,_,_,_,_,_,l), (_,_,_,_,_,_,_,_,_,_,_,ref l) => l } + (val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h, i, j, k, l) => a } + (val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h, i, j, k, l) => b } + (val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h, i, j, k, l) => c } + (val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h, i, j, k, l) => d } + (val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h, i, j, k, l) => e } + (val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h, i, j, k, l) => f } + (val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h, i, j, k, l) => g } + (val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h, i, j, k, l) => h } + (val8, ref8, mut8) -> I { (a, b, c, d, e, f, g, h, i, j, k, l) => i } + (val9, ref9, mut9) -> J { (a, b, c, d, e, f, g, h, i, j, k, l) => j } + (val10, ref10, mut10) -> K { (a, b, c, d, e, f, g, h, i, j, k, l) => k } + (val11, ref11, mut11) -> L { (a, b, c, d, e, f, g, h, i, j, k, l) => l } } } @@ -355,33 +362,29 @@ mod tests { } #[test] - fn test_n_tuple() { - let t = (0u8, 1u16, 2u32, 3u64, 4u, 5i8, 6i16, 7i32, 8i64, 9i, 10f32, 11f64); - assert_eq!(t.n0(), 0u8); - assert_eq!(t.n1(), 1u16); - assert_eq!(t.n2(), 2u32); - assert_eq!(t.n3(), 3u64); - assert_eq!(t.n4(), 4u); - assert_eq!(t.n5(), 5i8); - assert_eq!(t.n6(), 6i16); - assert_eq!(t.n7(), 7i32); - assert_eq!(t.n8(), 8i64); - assert_eq!(t.n9(), 9i); - assert_eq!(t.n10(), 10f32); - assert_eq!(t.n11(), 11f64); - - assert_eq!(t.n0_ref(), &0u8); - assert_eq!(t.n1_ref(), &1u16); - assert_eq!(t.n2_ref(), &2u32); - assert_eq!(t.n3_ref(), &3u64); - assert_eq!(t.n4_ref(), &4u); - assert_eq!(t.n5_ref(), &5i8); - assert_eq!(t.n6_ref(), &6i16); - assert_eq!(t.n7_ref(), &7i32); - assert_eq!(t.n8_ref(), &8i64); - assert_eq!(t.n9_ref(), &9i); - assert_eq!(t.n10_ref(), &10f32); - assert_eq!(t.n11_ref(), &11f64); + fn test_getters() { + macro_rules! test_getter( + ($x:expr, $valN:ident, $refN:ident, $mutN:ident, + $init:expr, $incr:expr, $result:expr) => ({ + assert_eq!($x.$valN(), $init); + assert_eq!(*$x.$refN(), $init); + *$x.$mutN() += $incr; + assert_eq!(*$x.$refN(), $result); + }) + ) + let mut x = (0u8, 1u16, 2u32, 3u64, 4u, 5i8, 6i16, 7i32, 8i64, 9i, 10f32, 11f64); + test_getter!(x, val0, ref0, mut0, 0, 1, 1); + test_getter!(x, val1, ref1, mut1, 1, 1, 2); + test_getter!(x, val2, ref2, mut2, 2, 1, 3); + test_getter!(x, val3, ref3, mut3, 3, 1, 4); + test_getter!(x, val4, ref4, mut4, 4, 1, 5); + test_getter!(x, val5, ref5, mut5, 5, 1, 6); + test_getter!(x, val6, ref6, mut6, 6, 1, 7); + test_getter!(x, val7, ref7, mut7, 7, 1, 8); + test_getter!(x, val8, ref8, mut8, 8, 1, 9); + test_getter!(x, val9, ref9, mut9, 9, 1, 10); + test_getter!(x, val10, ref10, mut10, 10.0, 1.0, 11.0); + test_getter!(x, val11, ref11, mut11, 11.0, 1.0, 12.0); } #[test] diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index 12e78629386..f0c3517a0b8 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -51,7 +51,7 @@ impl<'a> Iterator for AAGen<'a> { fn next(&mut self) -> Option { let r = self.rng.gen(); self.data.iter() - .skip_while(|pc| pc.n0() < r) + .skip_while(|pc| pc.val0() < r) .map(|&(_, c)| c) .next() } -- cgit 1.4.1-3-g733a5 From f450b2b379794ba9f367f9dadbd2d70913da8560 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 16 Feb 2014 20:36:43 +1100 Subject: Remove CloneableTuple and ImmutableTuple traits These are adequately covered by the Tuple2 trait. --- src/etc/vim/syntax/rust.vim | 4 -- src/libnative/io/process.rs | 4 +- src/librustc/middle/trans/consts.rs | 2 +- src/librustc/middle/ty.rs | 2 +- src/libstd/iter.rs | 2 +- src/libstd/prelude.rs | 1 - src/libstd/str.rs | 6 +-- src/libstd/tuple.rs | 77 +------------------------------- src/test/bench/task-perf-alloc-unwind.rs | 4 +- 9 files changed, 11 insertions(+), 91 deletions(-) (limited to 'src/libstd') diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index aac759e3950..03c67276049 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -95,13 +95,9 @@ syn keyword rustTrait Buffer Writer Reader Seek syn keyword rustTrait Str StrVector StrSlice OwnedStr IntoMaybeOwned syn keyword rustTrait IterBytes syn keyword rustTrait ToStr IntoStr -syn keyword rustTrait CloneableTuple ImmutableTuple syn keyword rustTrait Tuple1 Tuple2 Tuple3 Tuple4 syn keyword rustTrait Tuple5 Tuple6 Tuple7 Tuple8 syn keyword rustTrait Tuple9 Tuple10 Tuple11 Tuple12 -syn keyword rustTrait ImmutableTuple1 ImmutableTuple2 ImmutableTuple3 ImmutableTuple4 -syn keyword rustTrait ImmutableTuple5 ImmutableTuple6 ImmutableTuple7 ImmutableTuple8 -syn keyword rustTrait ImmutableTuple9 ImmutableTuple10 ImmutableTuple11 ImmutableTuple12 syn keyword rustTrait ImmutableEqVector ImmutableTotalOrdVector ImmutableCloneableVector syn keyword rustTrait OwnedVector OwnedCloneableVector OwnedEqVector MutableVector syn keyword rustTrait Vector VectorVector CloneableVector ImmutableVector diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs index 2a061c5f9b2..b796535371f 100644 --- a/src/libnative/io/process.rs +++ b/src/libnative/io/process.rs @@ -529,7 +529,7 @@ fn with_envp(env: Option<~[(~str, ~str)]>, cb: |*c_void| -> T) -> T { let mut tmps = vec::with_capacity(env.len()); for pair in env.iter() { - let kv = format!("{}={}", pair.first(), pair.second()); + let kv = format!("{}={}", *pair.ref0(), *pair.ref1()); tmps.push(kv.to_c_str()); } @@ -553,7 +553,7 @@ fn with_envp(env: Option<~[(~str, ~str)]>, cb: |*mut c_void| -> T) -> T { let mut blk = ~[]; for pair in env.iter() { - let kv = format!("{}={}", pair.first(), pair.second()); + let kv = format!("{}={}", *pair.ref0(), *pair.ref1()); blk.push_all(kv.as_bytes()); blk.push(0); } diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 68be851449a..fc5e48a161f 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -599,7 +599,7 @@ fn const_expr_unadjusted(cx: @CrateContext, e: &ast::Expr, const_eval::const_uint(i) => i as uint, _ => cx.sess.span_bug(count.span, "count must be integral const expression.") }; - let vs = vec::from_elem(n, const_expr(cx, elem, is_local).first()); + let vs = vec::from_elem(n, const_expr(cx, elem, is_local).val0()); let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) { C_struct(vs, false) } else { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 374f49a36be..0dcbfe491c3 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -4604,7 +4604,7 @@ pub fn determine_inherited_purity(parent: (ast::Purity, ast::NodeId), // purity inferred for it, then check it under its parent's purity. // Otherwise, use its own match child_sigil { - ast::BorrowedSigil if child.first() == ast::ImpureFn => parent, + ast::BorrowedSigil if child.val0() == ast::ImpureFn => parent, _ => child } } diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index d141da68dfd..e5a89fc42e1 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -2611,7 +2611,7 @@ mod tests { assert_eq!(vi.size_hint(), (10, Some(10))); assert_eq!(c.take(5).size_hint(), (5, Some(5))); - assert_eq!(c.skip(5).size_hint().second(), None); + assert_eq!(c.skip(5).size_hint().val1(), None); assert_eq!(c.take_while(|_| false).size_hint(), (0, None)); assert_eq!(c.skip_while(|_| false).size_hint(), (0, None)); assert_eq!(c.enumerate().size_hint(), (uint::MAX, None)); diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index ef159d68df7..bd21bb4e754 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -67,7 +67,6 @@ pub use io::{Buffer, Writer, Reader, Seek}; pub use str::{Str, StrVector, StrSlice, OwnedStr, IntoMaybeOwned}; pub use to_bytes::IterBytes; pub use to_str::{ToStr, IntoStr}; -pub use tuple::{CloneableTuple, ImmutableTuple}; pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4}; pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8}; pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12}; diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 023900e5d41..0a7f513581c 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -567,14 +567,14 @@ impl<'a> Iterator<&'a str> for StrSplits<'a> { // Helper functions used for Unicode normalization fn canonical_sort(comb: &mut [(char, u8)]) { use iter::range; - use tuple::CloneableTuple; + use tuple::Tuple2; let len = comb.len(); for i in range(0, len) { let mut swapped = false; for j in range(1, len-i) { - let classA = comb[j-1].second(); - let classB = comb[j].second(); + let classA = *comb[j-1].ref1(); + let classB = *comb[j].ref1(); if classA != 0 && classB != 0 && classA > classB { comb.swap(j-1, j); swapped = true; diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 91625a53c94..7a81e69f30a 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -19,66 +19,6 @@ use fmt; use result::{Ok, Err}; use to_str::ToStr; -/// Method extensions to pairs where both types satisfy the `Clone` bound -pub trait CloneableTuple { - /// Return the first element of self - fn first(&self) -> T; - /// Return the second element of self - fn second(&self) -> U; - /// Return the results of swapping the two elements of self - fn swap(&self) -> (U, T); -} - -impl CloneableTuple for (T, U) { - /// Return the first element of self - #[inline] - fn first(&self) -> T { - match *self { - (ref t, _) => (*t).clone(), - } - } - - /// Return the second element of self - #[inline] - fn second(&self) -> U { - match *self { - (_, ref u) => (*u).clone(), - } - } - - /// Return the results of swapping the two elements of self - #[inline] - fn swap(&self) -> (U, T) { - match (*self).clone() { - (t, u) => (u, t), - } - } -} - -/// Method extensions for pairs where the types don't necessarily satisfy the -/// `Clone` bound -pub trait ImmutableTuple { - /// Return a reference to the first element of self - fn first_ref<'a>(&'a self) -> &'a T; - /// Return a reference to the second element of self - fn second_ref<'a>(&'a self) -> &'a U; -} - -impl ImmutableTuple for (T, U) { - #[inline] - fn first_ref<'a>(&'a self) -> &'a T { - match *self { - (ref t, _) => t, - } - } - #[inline] - fn second_ref<'a>(&'a self) -> &'a U { - match *self { - (_, ref u) => u, - } - } -} - // macro for implementing n-ary tuple functions and operations macro_rules! tuple_impls { ($( @@ -339,26 +279,11 @@ mod tests { use clone::Clone; use cmp::*; - #[test] - fn test_tuple_ref() { - let x = (~"foo", ~"bar"); - assert_eq!(x.first_ref(), &~"foo"); - assert_eq!(x.second_ref(), &~"bar"); - } - - #[test] - fn test_tuple() { - assert_eq!((948, 4039.48).first(), 948); - assert_eq!((34.5, ~"foo").second(), ~"foo"); - assert_eq!(('a', 2).swap(), (2, 'a')); - } - #[test] fn test_clone() { let a = (1, ~"2"); let b = a.clone(); - assert_eq!(a.first(), b.first()); - assert_eq!(a.second(), b.second()); + assert_eq!(a, b); } #[test] diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index 013df3b3675..51eb65b1d5c 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -90,8 +90,8 @@ fn recurse_or_fail(depth: int, st: Option) { State { managed: @Cons((), st.managed), unique: ~Cons((), @*st.unique), - tuple: (@Cons((), st.tuple.first()), - ~Cons((), @*st.tuple.second())), + tuple: (@Cons((), st.tuple.ref0().clone()), + ~Cons((), @*st.tuple.ref1().clone())), vec: st.vec + &[@Cons((), *st.vec.last().unwrap())], res: r(@Cons((), st.res._l)) } -- cgit 1.4.1-3-g733a5