From f450b2b379794ba9f367f9dadbd2d70913da8560 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 16 Feb 2014 20:36:43 +1100 Subject: [PATCH] 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(-) diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index aac759e3950c..03c67276049e 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 2a061c5f9b20..b796535371f7 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 68be851449a9..fc5e48a161f1 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 374f49a36be5..0dcbfe491c31 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 d141da68dfd7..e5a89fc42e15 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 ef159d68df7e..bd21bb4e7544 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 023900e5d411..0a7f513581c0 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 91625a53c943..7a81e69f30ac 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 013df3b3675d..51eb65b1d5c7 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)) }