From f2af07e6d5254ca7b2bb5791afe5314fe6947128 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 11:45:50 -0500 Subject: [PATCH 01/35] libcollections: remove unnecessary `as_slice()` calls --- src/libcollections/binary_heap.rs | 6 ++-- src/libcollections/bit.rs | 18 +++++----- src/libcollections/btree/node.rs | 16 ++++----- src/libcollections/dlist.rs | 8 ++--- src/libcollections/enum_set.rs | 6 ++-- src/libcollections/ring_buf.rs | 12 +++---- src/libcollections/slice.rs | 60 +++++++++++++++---------------- src/libcollections/str.rs | 59 +++++++++++++++--------------- src/libcollections/string.rs | 46 ++++++++++++------------ src/libcollections/vec.rs | 17 +++++---- src/libcollections/vec_map.rs | 1 - 11 files changed, 123 insertions(+), 126 deletions(-) diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 330b93929746c..53d20aab24d61 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -769,8 +769,8 @@ mod tests { v.sort(); data.sort(); - assert_eq!(v.as_slice(), data.as_slice()); - assert_eq!(heap.into_sorted_vec().as_slice(), data.as_slice()); + assert_eq!(v, data); + assert_eq!(heap.into_sorted_vec(), data); } #[test] @@ -812,7 +812,7 @@ mod tests { fn test_from_iter() { let xs = vec!(9u, 8, 7, 6, 5, 4, 3, 2, 1); - let mut q: BinaryHeap = xs.as_slice().iter().rev().map(|&x| x).collect(); + let mut q: BinaryHeap = xs.iter().rev().map(|&x| x).collect(); for &x in xs.iter() { assert_eq!(q.pop().unwrap(), x); diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 903a9bd982324..953e432fd4a75 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -1692,10 +1692,10 @@ mod tests { #[test] fn test_to_str() { let zerolen = Bitv::new(); - assert_eq!(zerolen.to_string().as_slice(), ""); + assert_eq!(zerolen.to_string(), ""); let eightbits = Bitv::with_capacity(8u, false); - assert_eq!(eightbits.to_string().as_slice(), "00000000") + assert_eq!(eightbits.to_string(), "00000000") } #[test] @@ -1718,7 +1718,7 @@ mod tests { let mut b = bitv::Bitv::with_capacity(2, false); b.set(0, true); b.set(1, false); - assert_eq!(b.to_string().as_slice(), "10"); + assert_eq!(b.to_string(), "10"); } #[test] @@ -2029,7 +2029,7 @@ mod tests { fn test_from_bytes() { let bitv = from_bytes(&[0b10110110, 0b00000000, 0b11111111]); let str = format!("{}{}{}", "10110110", "00000000", "11111111"); - assert_eq!(bitv.to_string().as_slice(), str.as_slice()); + assert_eq!(bitv.to_string(), str); } #[test] @@ -2048,7 +2048,7 @@ mod tests { fn test_from_bools() { let bools = vec![true, false, true, true]; let bitv: Bitv = bools.iter().map(|n| *n).collect(); - assert_eq!(bitv.to_string().as_slice(), "1011"); + assert_eq!(bitv.to_string(), "1011"); } #[test] @@ -2207,7 +2207,7 @@ mod tests { let expected = [3, 5, 11, 77]; let actual = a.intersection(&b).collect::>(); - assert_eq!(actual.as_slice(), expected.as_slice()); + assert_eq!(actual, expected); } #[test] @@ -2226,7 +2226,7 @@ mod tests { let expected = [1, 5, 500]; let actual = a.difference(&b).collect::>(); - assert_eq!(actual.as_slice(), expected.as_slice()); + assert_eq!(actual, expected); } #[test] @@ -2247,7 +2247,7 @@ mod tests { let expected = [1, 5, 11, 14, 220]; let actual = a.symmetric_difference(&b).collect::>(); - assert_eq!(actual.as_slice(), expected.as_slice()); + assert_eq!(actual, expected); } #[test] @@ -2272,7 +2272,7 @@ mod tests { let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160, 200]; let actual = a.union(&b).collect::>(); - assert_eq!(actual.as_slice(), expected.as_slice()); + assert_eq!(actual, expected); } #[test] diff --git a/src/libcollections/btree/node.rs b/src/libcollections/btree/node.rs index b40ff35cca1c6..2c681b6b1d354 100644 --- a/src/libcollections/btree/node.rs +++ b/src/libcollections/btree/node.rs @@ -169,22 +169,22 @@ impl Node { /// Get the node's value at the given index pub fn val(&self, index: uint) -> Option<&V> { - self.vals.as_slice().get(index) + self.vals.get(index) } /// Get the node's value at the given index pub fn val_mut(&mut self, index: uint) -> Option<&mut V> { - self.vals.as_mut_slice().get_mut(index) + self.vals.get_mut(index) } /// Get the node's value mutably without any bounds checks. pub unsafe fn unsafe_val_mut(&mut self, index: uint) -> &mut V { - self.vals.as_mut_slice().unsafe_mut(index) + self.vals.unsafe_mut(index) } /// Get the node's edge at the given index pub fn edge(&self, index: uint) -> Option<&Node> { - self.edges.as_slice().get(index) + self.edges.get(index) } /// Get the node's edge mutably at the given index @@ -281,8 +281,8 @@ impl Node { pub fn iter<'a>(&'a self) -> Traversal<'a, K, V> { let is_leaf = self.is_leaf(); Traversal { - elems: self.keys.as_slice().iter().zip(self.vals.as_slice().iter()), - edges: self.edges.as_slice().iter(), + elems: self.keys.iter().zip(self.vals.iter()), + edges: self.edges.iter(), head_is_edge: true, tail_is_edge: true, has_edges: !is_leaf, @@ -292,7 +292,7 @@ impl Node { pub fn iter_mut<'a>(&'a mut self) -> MutTraversal<'a, K, V> { let is_leaf = self.is_leaf(); MutTraversal { - elems: self.keys.as_slice().iter().zip(self.vals.as_mut_slice().iter_mut()), + elems: self.keys.iter().zip(self.vals.as_mut_slice().iter_mut()), edges: self.edges.as_mut_slice().iter_mut(), head_is_edge: true, tail_is_edge: true, @@ -477,7 +477,7 @@ fn split(left: &mut Vec) -> Vec { let left_len = len - right_len; let mut right = Vec::with_capacity(left.capacity()); unsafe { - let left_ptr = left.as_slice().unsafe_get(left_len) as *const _; + let left_ptr = left.unsafe_get(left_len) as *const _; let right_ptr = right.as_mut_slice().as_mut_ptr(); ptr::copy_nonoverlapping_memory(right_ptr, left_ptr, right_len); left.set_len(left_len); diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 39cdf0c456413..a30bb9e978b50 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -926,7 +926,7 @@ mod tests { let mut m = list_from(v.as_slice()); m.prepend(list_from(u.as_slice())); check_links(&m); - u.extend(v.as_slice().iter().map(|&b| b)); + u.extend(v.iter().map(|&b| b)); assert_eq!(u.len(), m.len()); for elt in u.into_iter() { assert_eq!(m.pop_front(), Some(elt)) @@ -1133,7 +1133,7 @@ mod tests { spawn(proc() { check_links(&n); let a: &[_] = &[&1,&2,&3]; - assert_eq!(a, n.iter().collect::>().as_slice()); + assert_eq!(a, n.iter().collect::>()); }); } @@ -1224,12 +1224,12 @@ mod tests { #[test] fn test_show() { let list: DList = range(0i, 10).collect(); - assert!(list.to_string().as_slice() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); + assert!(list.to_string() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); let list: DList<&str> = vec!["just", "one", "test", "more"].iter() .map(|&s| s) .collect(); - assert!(list.to_string().as_slice() == "[just, one, test, more]"); + assert!(list.to_string() == "[just, one, test, more]"); } #[cfg(test)] diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index 2cbde0168a2e8..5e77cf66726a8 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -288,11 +288,11 @@ mod test { #[test] fn test_show() { let mut e = EnumSet::new(); - assert_eq!("{}", e.to_string().as_slice()); + assert_eq!("{}", e.to_string()); e.insert(A); - assert_eq!("{A}", e.to_string().as_slice()); + assert_eq!("{A}", e.to_string()); e.insert(C); - assert_eq!("{A, C}", e.to_string().as_slice()); + assert_eq!("{A, C}", e.to_string()); } #[test] diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index e11ba35367e2e..d9e5dde96ceee 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -1246,7 +1246,7 @@ mod tests { } { let b: &[_] = &[&0,&1,&2,&3,&4]; - assert_eq!(d.iter().collect::>().as_slice(), b); + assert_eq!(d.iter().collect::>(), b); } for i in range(6i, 9) { @@ -1254,7 +1254,7 @@ mod tests { } { let b: &[_] = &[&8,&7,&6,&0,&1,&2,&3,&4]; - assert_eq!(d.iter().collect::>().as_slice(), b); + assert_eq!(d.iter().collect::>(), b); } let mut it = d.iter(); @@ -1277,14 +1277,14 @@ mod tests { } { let b: &[_] = &[&4,&3,&2,&1,&0]; - assert_eq!(d.iter().rev().collect::>().as_slice(), b); + assert_eq!(d.iter().rev().collect::>(), b); } for i in range(6i, 9) { d.push_front(i); } let b: &[_] = &[&4,&3,&2,&1,&0,&6,&7,&8]; - assert_eq!(d.iter().rev().collect::>().as_slice(), b); + assert_eq!(d.iter().rev().collect::>(), b); } #[test] @@ -1495,12 +1495,12 @@ mod tests { #[test] fn test_show() { let ringbuf: RingBuf = range(0i, 10).collect(); - assert!(format!("{}", ringbuf).as_slice() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); + assert!(format!("{}", ringbuf) == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); let ringbuf: RingBuf<&str> = vec!["just", "one", "test", "more"].iter() .map(|&s| s) .collect(); - assert!(format!("{}", ringbuf).as_slice() == "[just, one, test, more]"); + assert!(format!("{}", ringbuf) == "[just, one, test, more]"); } #[test] diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 6c13abdaf892f..57e16fd7454ff 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1652,24 +1652,24 @@ mod tests { let xs = &[1i,2,3,4,5]; let splits: &[&[int]] = &[&[1], &[3], &[5]]; - assert_eq!(xs.split(|x| *x % 2 == 0).collect::>().as_slice(), + assert_eq!(xs.split(|x| *x % 2 == 0).collect::>(), splits); let splits: &[&[int]] = &[&[], &[2,3,4,5]]; - assert_eq!(xs.split(|x| *x == 1).collect::>().as_slice(), + assert_eq!(xs.split(|x| *x == 1).collect::>(), splits); let splits: &[&[int]] = &[&[1,2,3,4], &[]]; - assert_eq!(xs.split(|x| *x == 5).collect::>().as_slice(), + assert_eq!(xs.split(|x| *x == 5).collect::>(), splits); let splits: &[&[int]] = &[&[1,2,3,4,5]]; - assert_eq!(xs.split(|x| *x == 10).collect::>().as_slice(), + assert_eq!(xs.split(|x| *x == 10).collect::>(), splits); let splits: &[&[int]] = &[&[], &[], &[], &[], &[], &[]]; - assert_eq!(xs.split(|_| true).collect::>().as_slice(), + assert_eq!(xs.split(|_| true).collect::>(), splits); let xs: &[int] = &[]; let splits: &[&[int]] = &[&[]]; - assert_eq!(xs.split(|x| *x == 5).collect::>().as_slice(), splits); + assert_eq!(xs.split(|x| *x == 5).collect::>(), splits); } #[test] @@ -1677,18 +1677,18 @@ mod tests { let xs = &[1i,2,3,4,5]; let splits: &[&[int]] = &[&[1,2,3,4,5]]; - assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::>().as_slice(), + assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::>(), splits); let splits: &[&[int]] = &[&[1], &[3,4,5]]; - assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::>().as_slice(), + assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::>(), splits); let splits: &[&[int]] = &[&[], &[], &[], &[4,5]]; - assert_eq!(xs.splitn(3, |_| true).collect::>().as_slice(), + assert_eq!(xs.splitn(3, |_| true).collect::>(), splits); let xs: &[int] = &[]; let splits: &[&[int]] = &[&[]]; - assert_eq!(xs.splitn(1, |x| *x == 5).collect::>().as_slice(), splits); + assert_eq!(xs.splitn(1, |x| *x == 5).collect::>(), splits); } #[test] @@ -1696,18 +1696,18 @@ mod tests { let xs = &mut [1i,2,3,4,5]; let splits: &[&mut [int]] = &[&mut [1,2,3,4,5]]; - assert_eq!(xs.splitn_mut(0, |x| *x % 2 == 0).collect::>().as_slice(), + assert_eq!(xs.splitn_mut(0, |x| *x % 2 == 0).collect::>(), splits); let splits: &[&mut [int]] = &[&mut [1], &mut [3,4,5]]; - assert_eq!(xs.splitn_mut(1, |x| *x % 2 == 0).collect::>().as_slice(), + assert_eq!(xs.splitn_mut(1, |x| *x % 2 == 0).collect::>(), splits); let splits: &[&mut [int]] = &[&mut [], &mut [], &mut [], &mut [4,5]]; - assert_eq!(xs.splitn_mut(3, |_| true).collect::>().as_slice(), + assert_eq!(xs.splitn_mut(3, |_| true).collect::>(), splits); let xs: &mut [int] = &mut []; let splits: &[&mut [int]] = &[&mut []]; - assert_eq!(xs.splitn_mut(1, |x| *x == 5).collect::>().as_slice(), + assert_eq!(xs.splitn_mut(1, |x| *x == 5).collect::>(), splits); } @@ -1716,21 +1716,21 @@ mod tests { let xs = &[1i,2,3,4,5]; let splits: &[&[int]] = &[&[5], &[3], &[1]]; - assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::>().as_slice(), + assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::>(), splits); let splits: &[&[int]] = &[&[2,3,4,5], &[]]; - assert_eq!(xs.split(|x| *x == 1).rev().collect::>().as_slice(), + assert_eq!(xs.split(|x| *x == 1).rev().collect::>(), splits); let splits: &[&[int]] = &[&[], &[1,2,3,4]]; - assert_eq!(xs.split(|x| *x == 5).rev().collect::>().as_slice(), + assert_eq!(xs.split(|x| *x == 5).rev().collect::>(), splits); let splits: &[&[int]] = &[&[1,2,3,4,5]]; - assert_eq!(xs.split(|x| *x == 10).rev().collect::>().as_slice(), + assert_eq!(xs.split(|x| *x == 10).rev().collect::>(), splits); let xs: &[int] = &[]; let splits: &[&[int]] = &[&[]]; - assert_eq!(xs.split(|x| *x == 5).rev().collect::>().as_slice(), splits); + assert_eq!(xs.split(|x| *x == 5).rev().collect::>(), splits); } #[test] @@ -1738,18 +1738,18 @@ mod tests { let xs = &[1,2,3,4,5]; let splits: &[&[int]] = &[&[1,2,3,4,5]]; - assert_eq!(xs.rsplitn(0, |x| *x % 2 == 0).collect::>().as_slice(), + assert_eq!(xs.rsplitn(0, |x| *x % 2 == 0).collect::>(), splits); let splits: &[&[int]] = &[&[5], &[1,2,3]]; - assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::>().as_slice(), + assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::>(), splits); let splits: &[&[int]] = &[&[], &[], &[], &[1,2]]; - assert_eq!(xs.rsplitn(3, |_| true).collect::>().as_slice(), + assert_eq!(xs.rsplitn(3, |_| true).collect::>(), splits); let xs: &[int] = &[]; let splits: &[&[int]] = &[&[]]; - assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::>().as_slice(), splits); + assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::>(), splits); } #[test] @@ -1757,9 +1757,9 @@ mod tests { let v = &[1i,2,3,4]; let wins: &[&[int]] = &[&[1,2], &[2,3], &[3,4]]; - assert_eq!(v.windows(2).collect::>().as_slice(), wins); + assert_eq!(v.windows(2).collect::>(), wins); let wins: &[&[int]] = &[&[1i,2,3], &[2,3,4]]; - assert_eq!(v.windows(3).collect::>().as_slice(), wins); + assert_eq!(v.windows(3).collect::>(), wins); assert!(v.windows(6).next().is_none()); } @@ -1775,14 +1775,14 @@ mod tests { let v = &[1i,2,3,4,5]; let chunks: &[&[int]] = &[&[1i,2], &[3,4], &[5]]; - assert_eq!(v.chunks(2).collect::>().as_slice(), chunks); + assert_eq!(v.chunks(2).collect::>(), chunks); let chunks: &[&[int]] = &[&[1i,2,3], &[4,5]]; - assert_eq!(v.chunks(3).collect::>().as_slice(), chunks); + assert_eq!(v.chunks(3).collect::>(), chunks); let chunks: &[&[int]] = &[&[1i,2,3,4,5]]; - assert_eq!(v.chunks(6).collect::>().as_slice(), chunks); + assert_eq!(v.chunks(6).collect::>(), chunks); let chunks: &[&[int]] = &[&[5i], &[3,4], &[1,2]]; - assert_eq!(v.chunks(2).rev().collect::>().as_slice(), chunks); + assert_eq!(v.chunks(2).rev().collect::>(), chunks); let mut it = v.chunks(2); assert_eq!(it.indexable(), 3); let chunk: &[int] = &[1,2]; @@ -2081,7 +2081,7 @@ mod tests { fn test_to_vec() { let xs = box [1u, 2, 3]; let ys = xs.to_vec(); - assert_eq!(ys.as_slice(), [1u, 2, 3].as_slice()); + assert_eq!(ys, [1u, 2, 3]); } } diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index ad0a5e7617646..6e26962950ba2 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -215,7 +215,7 @@ pub struct Decompositions<'a> { impl<'a> Iterator for Decompositions<'a> { #[inline] fn next(&mut self) -> Option { - match self.buffer.as_slice().head() { + match self.buffer.head() { Some(&(c, 0)) => { self.sorted = false; self.buffer.remove(0); @@ -913,10 +913,10 @@ mod tests { #[test] fn test_collect() { let empty = String::from_str(""); - let s: String = empty.as_slice().chars().collect(); + let s: String = empty.chars().collect(); assert_eq!(empty, s); let data = String::from_str("ประเทศไทย中"); - let s: String = data.as_slice().chars().collect(); + let s: String = data.chars().collect(); assert_eq!(data, s); } @@ -924,7 +924,7 @@ mod tests { fn test_into_bytes() { let data = String::from_str("asdf"); let buf = data.into_bytes(); - assert_eq!(b"asdf", buf.as_slice()); + assert_eq!(b"asdf", buf); } #[test] @@ -941,21 +941,21 @@ mod tests { let string = "ประเทศไทย中华Việt Nam"; let mut data = String::from_str(string); data.push_str(string); - assert!(data.as_slice().find_str("ไท华").is_none()); - assert_eq!(data.as_slice().slice(0u, 43u).find_str(""), Some(0u)); - assert_eq!(data.as_slice().slice(6u, 43u).find_str(""), Some(6u - 6u)); + assert!(data.find_str("ไท华").is_none()); + assert_eq!(data.slice(0u, 43u).find_str(""), Some(0u)); + assert_eq!(data.slice(6u, 43u).find_str(""), Some(6u - 6u)); - assert_eq!(data.as_slice().slice(0u, 43u).find_str("ประ"), Some( 0u)); - assert_eq!(data.as_slice().slice(0u, 43u).find_str("ทศไ"), Some(12u)); - assert_eq!(data.as_slice().slice(0u, 43u).find_str("ย中"), Some(24u)); - assert_eq!(data.as_slice().slice(0u, 43u).find_str("iệt"), Some(34u)); - assert_eq!(data.as_slice().slice(0u, 43u).find_str("Nam"), Some(40u)); + assert_eq!(data.slice(0u, 43u).find_str("ประ"), Some( 0u)); + assert_eq!(data.slice(0u, 43u).find_str("ทศไ"), Some(12u)); + assert_eq!(data.slice(0u, 43u).find_str("ย中"), Some(24u)); + assert_eq!(data.slice(0u, 43u).find_str("iệt"), Some(34u)); + assert_eq!(data.slice(0u, 43u).find_str("Nam"), Some(40u)); - assert_eq!(data.as_slice().slice(43u, 86u).find_str("ประ"), Some(43u - 43u)); - assert_eq!(data.as_slice().slice(43u, 86u).find_str("ทศไ"), Some(55u - 43u)); - assert_eq!(data.as_slice().slice(43u, 86u).find_str("ย中"), Some(67u - 43u)); - assert_eq!(data.as_slice().slice(43u, 86u).find_str("iệt"), Some(77u - 43u)); - assert_eq!(data.as_slice().slice(43u, 86u).find_str("Nam"), Some(83u - 43u)); + assert_eq!(data.slice(43u, 86u).find_str("ประ"), Some(43u - 43u)); + assert_eq!(data.slice(43u, 86u).find_str("ทศไ"), Some(55u - 43u)); + assert_eq!(data.slice(43u, 86u).find_str("ย中"), Some(67u - 43u)); + assert_eq!(data.slice(43u, 86u).find_str("iệt"), Some(77u - 43u)); + assert_eq!(data.slice(43u, 86u).find_str("Nam"), Some(83u - 43u)); } #[test] @@ -987,7 +987,7 @@ mod tests { ($expected: expr, $string: expr) => { { let s = $string.concat(); - assert_eq!($expected, s.as_slice()); + assert_eq!($expected, s); } } } @@ -1025,7 +1025,7 @@ mod tests { ($expected: expr, $string: expr, $delim: expr) => { { let s = $string.connect($delim); - assert_eq!($expected, s.as_slice()); + assert_eq!($expected, s); } } } @@ -1146,7 +1146,7 @@ mod tests { let a = "ประเ"; let a2 = "دولة الكويتทศไทย中华"; - assert_eq!(data.replace(a, repl).as_slice(), a2); + assert_eq!(data.replace(a, repl), a2); } #[test] @@ -1156,7 +1156,7 @@ mod tests { let b = "ะเ"; let b2 = "ปรدولة الكويتทศไทย中华"; - assert_eq!(data.replace(b, repl).as_slice(), b2); + assert_eq!(data.replace(b, repl), b2); } #[test] @@ -1166,7 +1166,7 @@ mod tests { let c = "中华"; let c2 = "ประเทศไทยدولة الكويت"; - assert_eq!(data.replace(c, repl).as_slice(), c2); + assert_eq!(data.replace(c, repl), c2); } #[test] @@ -1175,7 +1175,7 @@ mod tests { let repl = "دولة الكويت"; let d = "ไท华"; - assert_eq!(data.replace(d, repl).as_slice(), data); + assert_eq!(data.replace(d, repl), data); } #[test] @@ -1211,7 +1211,7 @@ mod tests { } let letters = a_million_letter_x(); assert!(half_a_million_letter_x() == - String::from_str(letters.as_slice().slice(0u, 3u * 500000u))); + String::from_str(letters.slice(0u, 3u * 500000u))); } #[test] @@ -1450,7 +1450,7 @@ mod tests { let b: &[u8] = &[]; assert_eq!("".as_bytes(), b); assert_eq!("abc".as_bytes(), b"abc"); - assert_eq!("ศไทย中华Việt Nam".as_bytes(), v.as_slice()); + assert_eq!("ศไทย中华Việt Nam".as_bytes(), v); } #[test] @@ -1485,7 +1485,6 @@ mod tests { let string = "a\nb\nc"; let lines: Vec<&str> = string.lines().collect(); - let lines = lines.as_slice(); assert_eq!(string.subslice_offset(lines[0]), 0); assert_eq!(string.subslice_offset(lines[1]), 2); assert_eq!(string.subslice_offset(lines[2]), 4); @@ -2181,10 +2180,10 @@ mod tests { let s = "a̐éö̲\r\n"; let gr_inds = s.grapheme_indices(true).collect::>(); let b: &[_] = &[(0u, "a̐"), (3, "é"), (6, "ö̲"), (11, "\r\n")]; - assert_eq!(gr_inds.as_slice(), b); + assert_eq!(gr_inds, b); let gr_inds = s.grapheme_indices(true).rev().collect::>(); let b: &[_] = &[(11, "\r\n"), (6, "ö̲"), (3, "é"), (0u, "a̐")]; - assert_eq!(gr_inds.as_slice(), b); + assert_eq!(gr_inds, b); let mut gr_inds_iter = s.grapheme_indices(true); { let gr_inds = gr_inds_iter.by_ref(); @@ -2200,14 +2199,14 @@ mod tests { let s = "\n\r\n\r"; let gr = s.graphemes(true).rev().collect::>(); let b: &[_] = &["\r", "\r\n", "\n"]; - assert_eq!(gr.as_slice(), b); + assert_eq!(gr, b); } #[test] fn test_split_strator() { fn t(s: &str, sep: &str, u: &[&str]) { let v: Vec<&str> = s.split_str(sep).collect(); - assert_eq!(v.as_slice(), u.as_slice()); + assert_eq!(v, u); } t("--1233345--", "12345", &["--1233345--"]); t("abc::hello::there", "::", &["abc", "hello", "there"]); diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index fbb0bb5c4ce86..a7545d0696027 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -559,7 +559,7 @@ impl String { #[inline] #[unstable = "the panic conventions for strings are under development"] pub fn truncate(&mut self, new_len: uint) { - assert!(self.as_slice().is_char_boundary(new_len)); + assert!(self.is_char_boundary(new_len)); self.vec.truncate(new_len) } @@ -583,7 +583,7 @@ impl String { return None } - let CharRange {ch, next} = self.as_slice().char_range_at_reverse(len); + let CharRange {ch, next} = self.char_range_at_reverse(len); unsafe { self.vec.set_len(next); } @@ -618,7 +618,7 @@ impl String { let len = self.len(); if idx >= len { return None } - let CharRange { ch, next } = self.as_slice().char_range_at(idx); + let CharRange { ch, next } = self.char_range_at(idx); unsafe { ptr::copy_memory(self.vec.as_mut_ptr().offset(idx as int), self.vec.as_ptr().offset(next as int), @@ -643,7 +643,7 @@ impl String { pub fn insert(&mut self, idx: uint, ch: char) { let len = self.len(); assert!(idx <= len); - assert!(self.as_slice().is_char_boundary(idx)); + assert!(self.is_char_boundary(idx)); self.vec.reserve(4); let mut bits = [0, ..4]; let amt = ch.encode_utf8(&mut bits).unwrap(); @@ -1092,7 +1092,7 @@ mod tests { for p in pairs.iter() { let (s, u) = (*p).clone(); - let s_as_utf16 = s.as_slice().utf16_units().collect::>(); + let s_as_utf16 = s.utf16_units().collect::>(); let u_as_string = String::from_utf16(u.as_slice()).unwrap(); assert!(str::is_utf16(u.as_slice())); @@ -1102,7 +1102,7 @@ mod tests { assert_eq!(String::from_utf16_lossy(u.as_slice()), s); assert_eq!(String::from_utf16(s_as_utf16.as_slice()).unwrap(), s); - assert_eq!(u_as_string.as_slice().utf16_units().collect::>(), u); + assert_eq!(u_as_string.utf16_units().collect::>(), u); } } @@ -1162,18 +1162,18 @@ mod tests { let mv = s.as_mut_vec(); mv.push_all(&[b'D']); } - assert_eq!(s.as_slice(), "ABCD"); + assert_eq!(s, "ABCD"); } #[test] fn test_push_str() { let mut s = String::new(); s.push_str(""); - assert_eq!(s.as_slice().slice_from(0), ""); + assert_eq!(s.slice_from(0), ""); s.push_str("abc"); - assert_eq!(s.as_slice().slice_from(0), "abc"); + assert_eq!(s.slice_from(0), "abc"); s.push_str("ประเทศไทย中华Việt Nam"); - assert_eq!(s.as_slice().slice_from(0), "abcประเทศไทย中华Việt Nam"); + assert_eq!(s.slice_from(0), "abcประเทศไทย中华Việt Nam"); } #[test] @@ -1184,7 +1184,7 @@ mod tests { data.push('¢'); // 2 byte data.push('€'); // 3 byte data.push('𤭢'); // 4 byte - assert_eq!(data.as_slice(), "ประเทศไทย中华b¢€𤭢"); + assert_eq!(data, "ประเทศไทย中华b¢€𤭢"); } #[test] @@ -1195,24 +1195,24 @@ mod tests { assert_eq!(data.pop().unwrap(), '¢'); // 2 bytes assert_eq!(data.pop().unwrap(), 'b'); // 1 bytes assert_eq!(data.pop().unwrap(), '华'); - assert_eq!(data.as_slice(), "ประเทศไทย中"); + assert_eq!(data, "ประเทศไทย中"); } #[test] fn test_str_truncate() { let mut s = String::from_str("12345"); s.truncate(5); - assert_eq!(s.as_slice(), "12345"); + assert_eq!(s, "12345"); s.truncate(3); - assert_eq!(s.as_slice(), "123"); + assert_eq!(s, "123"); s.truncate(0); - assert_eq!(s.as_slice(), ""); + assert_eq!(s, ""); let mut s = String::from_str("12345"); - let p = s.as_slice().as_ptr(); + let p = s.as_ptr(); s.truncate(3); s.push_str("6"); - let p_ = s.as_slice().as_ptr(); + let p_ = s.as_ptr(); assert_eq!(p_, p); } @@ -1235,7 +1235,7 @@ mod tests { let mut s = String::from_str("12345"); s.clear(); assert_eq!(s.len(), 0); - assert_eq!(s.as_slice(), ""); + assert_eq!(s, ""); } #[test] @@ -1244,7 +1244,7 @@ mod tests { let b = a + "2"; let b = b + String::from_str("2"); assert_eq!(b.len(), 7); - assert_eq!(b.as_slice(), "1234522"); + assert_eq!(b, "1234522"); } #[test] @@ -1252,11 +1252,11 @@ mod tests { let mut s = "ศไทย中华Việt Nam; foobar".to_string();; assert_eq!(s.remove(0), Some('ศ')); assert_eq!(s.len(), 33); - assert_eq!(s.as_slice(), "ไทย中华Việt Nam; foobar"); + assert_eq!(s, "ไทย中华Việt Nam; foobar"); assert_eq!(s.remove(33), None); assert_eq!(s.remove(300), None); assert_eq!(s.remove(17), Some('ệ')); - assert_eq!(s.as_slice(), "ไทย中华Vit Nam; foobar"); + assert_eq!(s, "ไทย中华Vit Nam; foobar"); } #[test] #[should_fail] @@ -1268,9 +1268,9 @@ mod tests { fn insert() { let mut s = "foobar".to_string(); s.insert(0, 'ệ'); - assert_eq!(s.as_slice(), "ệfoobar"); + assert_eq!(s, "ệfoobar"); s.insert(6, 'ย'); - assert_eq!(s.as_slice(), "ệfooยbar"); + assert_eq!(s, "ệfooยbar"); } #[test] #[should_fail] fn insert_bad1() { "".to_string().insert(1, 't'); } diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 2396cf8cec67c..e2411ced632af 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -798,7 +798,7 @@ impl Vec { // decrement len before the read(), so a panic on Drop doesn't // re-drop the just-failed value. self.len -= 1; - ptr::read(self.as_slice().unsafe_get(self.len)); + ptr::read(self.unsafe_get(self.len)); } } } @@ -1091,7 +1091,7 @@ impl Vec { } else { unsafe { self.len -= 1; - Some(ptr::read(self.as_slice().unsafe_get(self.len()))) + Some(ptr::read(self.unsafe_get(self.len()))) } } } @@ -1779,7 +1779,7 @@ mod tests { #[test] fn test_as_vec() { let xs = [1u8, 2u8, 3u8]; - assert_eq!(as_vec(&xs).as_slice(), xs.as_slice()); + assert_eq!(as_vec(&xs).as_slice(), xs); } #[test] @@ -1875,7 +1875,7 @@ mod tests { } } - assert!(values.as_slice() == [1, 2, 5, 6, 7]); + assert!(values == [1, 2, 5, 6, 7]); } #[test] @@ -1889,7 +1889,7 @@ mod tests { } } - assert!(values.as_slice() == [2, 3, 3, 4, 5]); + assert!(values == [2, 3, 3, 4, 5]); } #[test] @@ -2019,7 +2019,6 @@ mod tests { let (left, right) = unzip(z1.iter().map(|&x| x)); - let (left, right) = (left.as_slice(), right.as_slice()); assert_eq!((1, 4), (left[0], right[0])); assert_eq!((2, 5), (left[1], right[1])); assert_eq!((3, 6), (left[2], right[2])); @@ -2153,7 +2152,7 @@ mod tests { #[test] fn test_map_in_place() { let v = vec![0u, 1, 2]; - assert_eq!(v.map_in_place(|i: uint| i as int - 1).as_slice(), [-1i, 0, 1].as_slice()); + assert_eq!(v.map_in_place(|i: uint| i as int - 1), [-1i, 0, 1]); } #[test] @@ -2161,7 +2160,7 @@ mod tests { let v = vec![(), ()]; #[deriving(PartialEq, Show)] struct ZeroSized; - assert_eq!(v.map_in_place(|_| ZeroSized).as_slice(), [ZeroSized, ZeroSized].as_slice()); + assert_eq!(v.map_in_place(|_| ZeroSized), [ZeroSized, ZeroSized]); } #[test] @@ -2198,7 +2197,7 @@ mod tests { fn test_into_boxed_slice() { let xs = vec![1u, 2, 3]; let ys = xs.into_boxed_slice(); - assert_eq!(ys.as_slice(), [1u, 2, 3].as_slice()); + assert_eq!(ys.as_slice(), [1u, 2, 3]); } #[bench] diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 986e7ef5bc24e..3be662c071c16 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -870,7 +870,6 @@ mod test_map { map.insert(3, 4i); let map_str = map.to_string(); - let map_str = map_str.as_slice(); assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}"); assert_eq!(format!("{}", empty), "{}".to_string()); } From 0ac3b166df97f34c43214d3c64da0cff66cbac7c Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:03:07 -0500 Subject: [PATCH 02/35] liballoc: remove unnecessary `as_slice()` calls --- src/liballoc/arc.rs | 2 +- src/liballoc/boxed.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 4f744b0b2dee1..64582d047f70d 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -521,7 +521,7 @@ mod tests { #[test] fn show_arc() { let a = Arc::new(5u32); - assert!(format!("{}", a).as_slice() == "5") + assert!(format!("{}", a) == "5") } // Make sure deriving works with Arc diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 000dda59e3dda..14ab45c9c01a9 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -169,14 +169,14 @@ mod test { let b = box Test as Box; let a_str = a.to_str(); let b_str = b.to_str(); - assert_eq!(a_str.as_slice(), "Box"); - assert_eq!(b_str.as_slice(), "Box"); + assert_eq!(a_str, "Box"); + assert_eq!(b_str, "Box"); let a = &8u as &Any; let b = &Test as &Any; let s = format!("{}", a); - assert_eq!(s.as_slice(), "&Any"); + assert_eq!(s, "&Any"); let s = format!("{}", b); - assert_eq!(s.as_slice(), "&Any"); + assert_eq!(s, "&Any"); } } From 5257a5b284038d704011c90f14140c16c5a37f7d Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:12:30 -0500 Subject: [PATCH 03/35] libcoretest: remove unnecessary `as_slice()` calls --- src/libcoretest/cell.rs | 8 +- src/libcoretest/char.rs | 38 +++---- src/libcoretest/fmt/num.rs | 214 ++++++++++++++++++------------------- src/libcoretest/option.rs | 8 +- src/libcoretest/result.rs | 4 +- src/libcoretest/tuple.rs | 6 +- 6 files changed, 139 insertions(+), 139 deletions(-) diff --git a/src/libcoretest/cell.rs b/src/libcoretest/cell.rs index 6444cf7ee0ebf..54da6264bb049 100644 --- a/src/libcoretest/cell.rs +++ b/src/libcoretest/cell.rs @@ -29,10 +29,10 @@ fn smoketest_cell() { #[test] fn cell_has_sensible_show() { let x = Cell::new("foo bar"); - assert!(format!("{}", x).as_slice().contains(x.get())); + assert!(format!("{}", x).contains(x.get())); x.set("baz qux"); - assert!(format!("{}", x).as_slice().contains(x.get())); + assert!(format!("{}", x).contains(x.get())); } #[test] @@ -40,11 +40,11 @@ fn ref_and_refmut_have_sensible_show() { let refcell = RefCell::new("foo"); let refcell_refmut = refcell.borrow_mut(); - assert!(format!("{}", refcell_refmut).as_slice().contains("foo")); + assert!(format!("{}", refcell_refmut).contains("foo")); drop(refcell_refmut); let refcell_ref = refcell.borrow(); - assert!(format!("{}", refcell_ref).as_slice().contains("foo")); + assert!(format!("{}", refcell_ref).contains("foo")); drop(refcell_ref); } diff --git a/src/libcoretest/char.rs b/src/libcoretest/char.rs index 507ddf65e55b3..e5561bebb22d8 100644 --- a/src/libcoretest/char.rs +++ b/src/libcoretest/char.rs @@ -121,31 +121,31 @@ fn test_escape_default() { return result; } let s = string('\n'); - assert_eq!(s.as_slice(), "\\n"); + assert_eq!(s, "\\n"); let s = string('\r'); - assert_eq!(s.as_slice(), "\\r"); + assert_eq!(s, "\\r"); let s = string('\''); - assert_eq!(s.as_slice(), "\\'"); + assert_eq!(s, "\\'"); let s = string('"'); - assert_eq!(s.as_slice(), "\\\""); + assert_eq!(s, "\\\""); let s = string(' '); - assert_eq!(s.as_slice(), " "); + assert_eq!(s, " "); let s = string('a'); - assert_eq!(s.as_slice(), "a"); + assert_eq!(s, "a"); let s = string('~'); - assert_eq!(s.as_slice(), "~"); + assert_eq!(s, "~"); let s = string('\x00'); - assert_eq!(s.as_slice(), "\\x00"); + assert_eq!(s, "\\x00"); let s = string('\x1f'); - assert_eq!(s.as_slice(), "\\x1f"); + assert_eq!(s, "\\x1f"); let s = string('\x7f'); - assert_eq!(s.as_slice(), "\\x7f"); + assert_eq!(s, "\\x7f"); let s = string('\u00ff'); - assert_eq!(s.as_slice(), "\\u00ff"); + assert_eq!(s, "\\u00ff"); let s = string('\u011b'); - assert_eq!(s.as_slice(), "\\u011b"); + assert_eq!(s, "\\u011b"); let s = string('\U0001d4b6'); - assert_eq!(s.as_slice(), "\\U0001d4b6"); + assert_eq!(s, "\\U0001d4b6"); } #[test] @@ -156,17 +156,17 @@ fn test_escape_unicode() { return result; } let s = string('\x00'); - assert_eq!(s.as_slice(), "\\x00"); + assert_eq!(s, "\\x00"); let s = string('\n'); - assert_eq!(s.as_slice(), "\\x0a"); + assert_eq!(s, "\\x0a"); let s = string(' '); - assert_eq!(s.as_slice(), "\\x20"); + assert_eq!(s, "\\x20"); let s = string('a'); - assert_eq!(s.as_slice(), "\\x61"); + assert_eq!(s, "\\x61"); let s = string('\u011b'); - assert_eq!(s.as_slice(), "\\u011b"); + assert_eq!(s, "\\u011b"); let s = string('\U0001d4b6'); - assert_eq!(s.as_slice(), "\\U0001d4b6"); + assert_eq!(s, "\\U0001d4b6"); } #[test] diff --git a/src/libcoretest/fmt/num.rs b/src/libcoretest/fmt/num.rs index 3b43d6ad33b44..1e28933becd6e 100644 --- a/src/libcoretest/fmt/num.rs +++ b/src/libcoretest/fmt/num.rs @@ -16,136 +16,136 @@ fn test_format_int() { // Formatting integers should select the right implementation based off // the type of the argument. Also, hex/octal/binary should be defined // for integers, but they shouldn't emit the negative sign. - assert!(format!("{}", 1i).as_slice() == "1"); - assert!(format!("{}", 1i8).as_slice() == "1"); - assert!(format!("{}", 1i16).as_slice() == "1"); - assert!(format!("{}", 1i32).as_slice() == "1"); - assert!(format!("{}", 1i64).as_slice() == "1"); - assert!(format!("{}", -1i).as_slice() == "-1"); - assert!(format!("{}", -1i8).as_slice() == "-1"); - assert!(format!("{}", -1i16).as_slice() == "-1"); - assert!(format!("{}", -1i32).as_slice() == "-1"); - assert!(format!("{}", -1i64).as_slice() == "-1"); - assert!(format!("{:b}", 1i).as_slice() == "1"); - assert!(format!("{:b}", 1i8).as_slice() == "1"); - assert!(format!("{:b}", 1i16).as_slice() == "1"); - assert!(format!("{:b}", 1i32).as_slice() == "1"); - assert!(format!("{:b}", 1i64).as_slice() == "1"); - assert!(format!("{:x}", 1i).as_slice() == "1"); - assert!(format!("{:x}", 1i8).as_slice() == "1"); - assert!(format!("{:x}", 1i16).as_slice() == "1"); - assert!(format!("{:x}", 1i32).as_slice() == "1"); - assert!(format!("{:x}", 1i64).as_slice() == "1"); - assert!(format!("{:X}", 1i).as_slice() == "1"); - assert!(format!("{:X}", 1i8).as_slice() == "1"); - assert!(format!("{:X}", 1i16).as_slice() == "1"); - assert!(format!("{:X}", 1i32).as_slice() == "1"); - assert!(format!("{:X}", 1i64).as_slice() == "1"); - assert!(format!("{:o}", 1i).as_slice() == "1"); - assert!(format!("{:o}", 1i8).as_slice() == "1"); - assert!(format!("{:o}", 1i16).as_slice() == "1"); - assert!(format!("{:o}", 1i32).as_slice() == "1"); - assert!(format!("{:o}", 1i64).as_slice() == "1"); - - assert!(format!("{}", 1u).as_slice() == "1"); - assert!(format!("{}", 1u8).as_slice() == "1"); - assert!(format!("{}", 1u16).as_slice() == "1"); - assert!(format!("{}", 1u32).as_slice() == "1"); - assert!(format!("{}", 1u64).as_slice() == "1"); - assert!(format!("{:b}", 1u).as_slice() == "1"); - assert!(format!("{:b}", 1u8).as_slice() == "1"); - assert!(format!("{:b}", 1u16).as_slice() == "1"); - assert!(format!("{:b}", 1u32).as_slice() == "1"); - assert!(format!("{:b}", 1u64).as_slice() == "1"); - assert!(format!("{:x}", 1u).as_slice() == "1"); - assert!(format!("{:x}", 1u8).as_slice() == "1"); - assert!(format!("{:x}", 1u16).as_slice() == "1"); - assert!(format!("{:x}", 1u32).as_slice() == "1"); - assert!(format!("{:x}", 1u64).as_slice() == "1"); - assert!(format!("{:X}", 1u).as_slice() == "1"); - assert!(format!("{:X}", 1u8).as_slice() == "1"); - assert!(format!("{:X}", 1u16).as_slice() == "1"); - assert!(format!("{:X}", 1u32).as_slice() == "1"); - assert!(format!("{:X}", 1u64).as_slice() == "1"); - assert!(format!("{:o}", 1u).as_slice() == "1"); - assert!(format!("{:o}", 1u8).as_slice() == "1"); - assert!(format!("{:o}", 1u16).as_slice() == "1"); - assert!(format!("{:o}", 1u32).as_slice() == "1"); - assert!(format!("{:o}", 1u64).as_slice() == "1"); + assert!(format!("{}", 1i) == "1"); + assert!(format!("{}", 1i8) == "1"); + assert!(format!("{}", 1i16) == "1"); + assert!(format!("{}", 1i32) == "1"); + assert!(format!("{}", 1i64) == "1"); + assert!(format!("{}", -1i) == "-1"); + assert!(format!("{}", -1i8) == "-1"); + assert!(format!("{}", -1i16) == "-1"); + assert!(format!("{}", -1i32) == "-1"); + assert!(format!("{}", -1i64) == "-1"); + assert!(format!("{:b}", 1i) == "1"); + assert!(format!("{:b}", 1i8) == "1"); + assert!(format!("{:b}", 1i16) == "1"); + assert!(format!("{:b}", 1i32) == "1"); + assert!(format!("{:b}", 1i64) == "1"); + assert!(format!("{:x}", 1i) == "1"); + assert!(format!("{:x}", 1i8) == "1"); + assert!(format!("{:x}", 1i16) == "1"); + assert!(format!("{:x}", 1i32) == "1"); + assert!(format!("{:x}", 1i64) == "1"); + assert!(format!("{:X}", 1i) == "1"); + assert!(format!("{:X}", 1i8) == "1"); + assert!(format!("{:X}", 1i16) == "1"); + assert!(format!("{:X}", 1i32) == "1"); + assert!(format!("{:X}", 1i64) == "1"); + assert!(format!("{:o}", 1i) == "1"); + assert!(format!("{:o}", 1i8) == "1"); + assert!(format!("{:o}", 1i16) == "1"); + assert!(format!("{:o}", 1i32) == "1"); + assert!(format!("{:o}", 1i64) == "1"); + + assert!(format!("{}", 1u) == "1"); + assert!(format!("{}", 1u8) == "1"); + assert!(format!("{}", 1u16) == "1"); + assert!(format!("{}", 1u32) == "1"); + assert!(format!("{}", 1u64) == "1"); + assert!(format!("{:b}", 1u) == "1"); + assert!(format!("{:b}", 1u8) == "1"); + assert!(format!("{:b}", 1u16) == "1"); + assert!(format!("{:b}", 1u32) == "1"); + assert!(format!("{:b}", 1u64) == "1"); + assert!(format!("{:x}", 1u) == "1"); + assert!(format!("{:x}", 1u8) == "1"); + assert!(format!("{:x}", 1u16) == "1"); + assert!(format!("{:x}", 1u32) == "1"); + assert!(format!("{:x}", 1u64) == "1"); + assert!(format!("{:X}", 1u) == "1"); + assert!(format!("{:X}", 1u8) == "1"); + assert!(format!("{:X}", 1u16) == "1"); + assert!(format!("{:X}", 1u32) == "1"); + assert!(format!("{:X}", 1u64) == "1"); + assert!(format!("{:o}", 1u) == "1"); + assert!(format!("{:o}", 1u8) == "1"); + assert!(format!("{:o}", 1u16) == "1"); + assert!(format!("{:o}", 1u32) == "1"); + assert!(format!("{:o}", 1u64) == "1"); // Test a larger number - assert!(format!("{:b}", 55i).as_slice() == "110111"); - assert!(format!("{:o}", 55i).as_slice() == "67"); - assert!(format!("{}", 55i).as_slice() == "55"); - assert!(format!("{:x}", 55i).as_slice() == "37"); - assert!(format!("{:X}", 55i).as_slice() == "37"); + assert!(format!("{:b}", 55i) == "110111"); + assert!(format!("{:o}", 55i) == "67"); + assert!(format!("{}", 55i) == "55"); + assert!(format!("{:x}", 55i) == "37"); + assert!(format!("{:X}", 55i) == "37"); } #[test] fn test_format_int_zero() { - assert!(format!("{}", 0i).as_slice() == "0"); - assert!(format!("{:b}", 0i).as_slice() == "0"); - assert!(format!("{:o}", 0i).as_slice() == "0"); - assert!(format!("{:x}", 0i).as_slice() == "0"); - assert!(format!("{:X}", 0i).as_slice() == "0"); - - assert!(format!("{}", 0u).as_slice() == "0"); - assert!(format!("{:b}", 0u).as_slice() == "0"); - assert!(format!("{:o}", 0u).as_slice() == "0"); - assert!(format!("{:x}", 0u).as_slice() == "0"); - assert!(format!("{:X}", 0u).as_slice() == "0"); + assert!(format!("{}", 0i) == "0"); + assert!(format!("{:b}", 0i) == "0"); + assert!(format!("{:o}", 0i) == "0"); + assert!(format!("{:x}", 0i) == "0"); + assert!(format!("{:X}", 0i) == "0"); + + assert!(format!("{}", 0u) == "0"); + assert!(format!("{:b}", 0u) == "0"); + assert!(format!("{:o}", 0u) == "0"); + assert!(format!("{:x}", 0u) == "0"); + assert!(format!("{:X}", 0u) == "0"); } #[test] fn test_format_int_flags() { - assert!(format!("{:3}", 1i).as_slice() == " 1"); - assert!(format!("{:>3}", 1i).as_slice() == " 1"); - assert!(format!("{:>+3}", 1i).as_slice() == " +1"); - assert!(format!("{:<3}", 1i).as_slice() == "1 "); - assert!(format!("{:#}", 1i).as_slice() == "1"); - assert!(format!("{:#x}", 10i).as_slice() == "0xa"); - assert!(format!("{:#X}", 10i).as_slice() == "0xA"); - assert!(format!("{:#5x}", 10i).as_slice() == " 0xa"); - assert!(format!("{:#o}", 10i).as_slice() == "0o12"); - assert!(format!("{:08x}", 10i).as_slice() == "0000000a"); - assert!(format!("{:8x}", 10i).as_slice() == " a"); - assert!(format!("{:<8x}", 10i).as_slice() == "a "); - assert!(format!("{:>8x}", 10i).as_slice() == " a"); - assert!(format!("{:#08x}", 10i).as_slice() == "0x00000a"); - assert!(format!("{:08}", -10i).as_slice() == "-0000010"); - assert!(format!("{:x}", -1u8).as_slice() == "ff"); - assert!(format!("{:X}", -1u8).as_slice() == "FF"); - assert!(format!("{:b}", -1u8).as_slice() == "11111111"); - assert!(format!("{:o}", -1u8).as_slice() == "377"); - assert!(format!("{:#x}", -1u8).as_slice() == "0xff"); - assert!(format!("{:#X}", -1u8).as_slice() == "0xFF"); - assert!(format!("{:#b}", -1u8).as_slice() == "0b11111111"); - assert!(format!("{:#o}", -1u8).as_slice() == "0o377"); + assert!(format!("{:3}", 1i) == " 1"); + assert!(format!("{:>3}", 1i) == " 1"); + assert!(format!("{:>+3}", 1i) == " +1"); + assert!(format!("{:<3}", 1i) == "1 "); + assert!(format!("{:#}", 1i) == "1"); + assert!(format!("{:#x}", 10i) == "0xa"); + assert!(format!("{:#X}", 10i) == "0xA"); + assert!(format!("{:#5x}", 10i) == " 0xa"); + assert!(format!("{:#o}", 10i) == "0o12"); + assert!(format!("{:08x}", 10i) == "0000000a"); + assert!(format!("{:8x}", 10i) == " a"); + assert!(format!("{:<8x}", 10i) == "a "); + assert!(format!("{:>8x}", 10i) == " a"); + assert!(format!("{:#08x}", 10i) == "0x00000a"); + assert!(format!("{:08}", -10i) == "-0000010"); + assert!(format!("{:x}", -1u8) == "ff"); + assert!(format!("{:X}", -1u8) == "FF"); + assert!(format!("{:b}", -1u8) == "11111111"); + assert!(format!("{:o}", -1u8) == "377"); + assert!(format!("{:#x}", -1u8) == "0xff"); + assert!(format!("{:#X}", -1u8) == "0xFF"); + assert!(format!("{:#b}", -1u8) == "0b11111111"); + assert!(format!("{:#o}", -1u8) == "0o377"); } #[test] fn test_format_int_sign_padding() { - assert!(format!("{:+5}", 1i).as_slice() == " +1"); - assert!(format!("{:+5}", -1i).as_slice() == " -1"); - assert!(format!("{:05}", 1i).as_slice() == "00001"); - assert!(format!("{:05}", -1i).as_slice() == "-0001"); - assert!(format!("{:+05}", 1i).as_slice() == "+0001"); - assert!(format!("{:+05}", -1i).as_slice() == "-0001"); + assert!(format!("{:+5}", 1i) == " +1"); + assert!(format!("{:+5}", -1i) == " -1"); + assert!(format!("{:05}", 1i) == "00001"); + assert!(format!("{:05}", -1i) == "-0001"); + assert!(format!("{:+05}", 1i) == "+0001"); + assert!(format!("{:+05}", -1i) == "-0001"); } #[test] fn test_format_int_twos_complement() { use core::{i8, i16, i32, i64}; - assert!(format!("{}", i8::MIN).as_slice() == "-128"); - assert!(format!("{}", i16::MIN).as_slice() == "-32768"); - assert!(format!("{}", i32::MIN).as_slice() == "-2147483648"); - assert!(format!("{}", i64::MIN).as_slice() == "-9223372036854775808"); + assert!(format!("{}", i8::MIN) == "-128"); + assert!(format!("{}", i16::MIN) == "-32768"); + assert!(format!("{}", i32::MIN) == "-2147483648"); + assert!(format!("{}", i64::MIN) == "-9223372036854775808"); } #[test] fn test_format_radix() { - assert!(format!("{:04}", radix(3i, 2)).as_slice() == "0011"); - assert!(format!("{}", radix(55i, 36)).as_slice() == "1j"); + assert!(format!("{:04}", radix(3i, 2)) == "0011"); + assert!(format!("{}", radix(55i, 36)) == "1j"); } #[test] diff --git a/src/libcoretest/option.rs b/src/libcoretest/option.rs index a5927d47eb0af..86fc25c9d918c 100644 --- a/src/libcoretest/option.rs +++ b/src/libcoretest/option.rs @@ -28,10 +28,10 @@ fn test_get_ptr() { #[test] fn test_get_str() { let x = "test".to_string(); - let addr_x = x.as_slice().as_ptr(); + let addr_x = x.as_ptr(); let opt = Some(x); let y = opt.unwrap(); - let addr_y = y.as_slice().as_ptr(); + let addr_y = y.as_ptr(); assert_eq!(addr_x, addr_y); } @@ -135,7 +135,7 @@ fn test_or_else() { fn test_unwrap() { assert_eq!(Some(1i).unwrap(), 1); let s = Some("hello".to_string()).unwrap(); - assert_eq!(s.as_slice(), "hello"); + assert_eq!(s, "hello"); } #[test] @@ -266,4 +266,4 @@ fn test_cloned() { assert_eq!(opt_ref_ref.clone(), Some(&val1_ref)); assert_eq!(opt_ref_ref.clone().cloned(), Some(&val1)); assert_eq!(opt_ref_ref.cloned().cloned(), Some(1u32)); -} \ No newline at end of file +} diff --git a/src/libcoretest/result.rs b/src/libcoretest/result.rs index 92124e2f299cd..415cd4e7dcfb8 100644 --- a/src/libcoretest/result.rs +++ b/src/libcoretest/result.rs @@ -93,9 +93,9 @@ pub fn test_fmt_default() { let err: Result = Err("Err"); let s = format!("{}", ok); - assert_eq!(s.as_slice(), "Ok(100)"); + assert_eq!(s, "Ok(100)"); let s = format!("{}", err); - assert_eq!(s.as_slice(), "Err(Err)"); + assert_eq!(s, "Err(Err)"); } #[test] diff --git a/src/libcoretest/tuple.rs b/src/libcoretest/tuple.rs index be71e42ae9ad6..c53d82de23c6c 100644 --- a/src/libcoretest/tuple.rs +++ b/src/libcoretest/tuple.rs @@ -84,9 +84,9 @@ fn test_tuple_cmp() { #[test] fn test_show() { let s = format!("{}", (1i,)); - assert_eq!(s.as_slice(), "(1,)"); + assert_eq!(s, "(1,)"); let s = format!("{}", (1i, true)); - assert_eq!(s.as_slice(), "(1, true)"); + assert_eq!(s, "(1, true)"); let s = format!("{}", (1i, "hi", true)); - assert_eq!(s.as_slice(), "(1, hi, true)"); + assert_eq!(s, "(1, hi, true)"); } From 0f54f32a9cd6455871ba87f65e8ee9b22ce58670 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:14:37 -0500 Subject: [PATCH 04/35] libflate: remove unnecessary `as_slice()` calls --- src/libflate/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs index 0318509751bd5..cc36c2eef4552 100644 --- a/src/libflate/lib.rs +++ b/src/libflate/lib.rs @@ -128,7 +128,7 @@ mod tests { debug!("{} bytes deflated to {} ({:.1}% size)", input.len(), cmp.len(), 100.0 * ((cmp.len() as f64) / (input.len() as f64))); - assert_eq!(input.as_slice(), out.as_slice()); + assert_eq!(input, out.as_slice()); } } @@ -137,6 +137,6 @@ mod tests { let bytes = vec!(1, 2, 3, 4, 5); let deflated = deflate_bytes(bytes.as_slice()).expect("deflation failed"); let inflated = inflate_bytes(deflated.as_slice()).expect("inflation failed"); - assert_eq!(inflated.as_slice(), bytes.as_slice()); + assert_eq!(inflated.as_slice(), bytes); } } From a7960136aca69d44bbe429a8690ca05391e5e349 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:15:18 -0500 Subject: [PATCH 05/35] libfmt_macros: remove unnecessary `as_slice()` calls --- src/libfmt_macros/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 03b65b3f71c84..d88551eb85561 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -440,7 +440,7 @@ mod tests { fn same(fmt: &'static str, p: &[Piece<'static>]) { let mut parser = Parser::new(fmt); - assert!(p == parser.collect::>>().as_slice()); + assert!(p == parser.collect::>>()); } fn fmtdflt() -> FormatSpec<'static> { From 6efc87945bf76332bbcee4f60188a505f6dc869d Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:18:39 -0500 Subject: [PATCH 06/35] libgetops: remove unnecessary `as_slice()` calls --- src/libgetopts/lib.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 1204ac18f99dc..19af3f595b286 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -244,7 +244,7 @@ impl OptGroup { aliases: Vec::new() }, (1,0) => Opt { - name: Short(short_name.as_slice().char_at(0)), + name: Short(short_name.char_at(0)), hasarg: hasarg, occur: occur, aliases: Vec::new() @@ -255,7 +255,7 @@ impl OptGroup { occur: occur, aliases: vec!( Opt { - name: Short(short_name.as_slice().char_at(0)), + name: Short(short_name.char_at(0)), hasarg: hasarg, occur: occur, aliases: Vec::new() @@ -576,7 +576,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result { let curlen = cur.len(); if !is_arg(cur.as_slice()) { free.push(cur); - } else if cur.as_slice() == "--" { + } else if cur == "--" { let mut j = i + 1; while j < l { free.push(args[j].clone()); j += 1; } break; @@ -584,7 +584,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result { let mut names; let mut i_arg = None; if cur.as_bytes()[1] == b'-' { - let tail = cur.as_slice().slice(2, curlen); + let tail = cur.slice(2, curlen); let tail_eq: Vec<&str> = tail.split('=').collect(); if tail_eq.len() <= 1 { names = vec!(Long(tail.to_string())); @@ -597,7 +597,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result { let mut j = 1; names = Vec::new(); while j < curlen { - let range = cur.as_slice().char_range_at(j); + let range = cur.char_range_at(j); let opt = Short(range.ch); /* In a series of potential options (eg. -aheJ), if we @@ -620,8 +620,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result { }; if arg_follows && range.next < curlen { - i_arg = Some(cur.as_slice() - .slice(range.next, curlen).to_string()); + i_arg = Some(cur.slice(range.next, curlen).to_string()); break; } @@ -736,7 +735,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String { // FIXME: #5516 should be graphemes not codepoints // here we just need to indent the start of the description - let rowlen = row.as_slice().char_len(); + let rowlen = row.char_len(); if rowlen < 24 { for _ in range(0, 24 - rowlen) { row.push(' '); @@ -747,7 +746,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String { // Normalize desc to contain words separated by one space character let mut desc_normalized_whitespace = String::new(); - for word in desc.as_slice().words() { + for word in desc.words() { desc_normalized_whitespace.push_str(word); desc_normalized_whitespace.push(' '); } From c0ef959b31bb2f9c1df811f51c5aab6c1d9ca3dc Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:19:57 -0500 Subject: [PATCH 07/35] libgraphviz: remove unnecessary `as_slice()` calls --- src/libgraphviz/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index 0a5081d07be00..c1c397db213f6 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -439,7 +439,7 @@ impl<'a> LabelText<'a> { /// Renders text as string suitable for a label in a .dot file. pub fn escape(&self) -> String { match self { - &LabelStr(ref s) => s.as_slice().escape_default(), + &LabelStr(ref s) => s.escape_default(), &EscStr(ref s) => LabelText::escape_str(s.as_slice()), } } @@ -709,7 +709,7 @@ mod tests { fn empty_graph() { let labels : Trivial = UnlabelledNodes(0); let r = test_input(LabelledGraph::new("empty_graph", labels, vec!())); - assert_eq!(r.unwrap().as_slice(), + assert_eq!(r.unwrap(), r#"digraph empty_graph { } "#); @@ -719,7 +719,7 @@ r#"digraph empty_graph { fn single_node() { let labels : Trivial = UnlabelledNodes(1); let r = test_input(LabelledGraph::new("single_node", labels, vec!())); - assert_eq!(r.unwrap().as_slice(), + assert_eq!(r.unwrap(), r#"digraph single_node { N0[label="N0"]; } @@ -731,7 +731,7 @@ r#"digraph single_node { let labels : Trivial = UnlabelledNodes(2); let result = test_input(LabelledGraph::new("single_edge", labels, vec!(edge(0, 1, "E")))); - assert_eq!(result.unwrap().as_slice(), + assert_eq!(result.unwrap(), r#"digraph single_edge { N0[label="N0"]; N1[label="N1"]; @@ -745,7 +745,7 @@ r#"digraph single_edge { let labels : Trivial = SomeNodesLabelled(vec![Some("A"), None]); let result = test_input(LabelledGraph::new("test_some_labelled", labels, vec![edge(0, 1, "A-1")])); - assert_eq!(result.unwrap().as_slice(), + assert_eq!(result.unwrap(), r#"digraph test_some_labelled { N0[label="A"]; N1[label="N1"]; @@ -759,7 +759,7 @@ r#"digraph test_some_labelled { let labels : Trivial = UnlabelledNodes(1); let r = test_input(LabelledGraph::new("single_cyclic_node", labels, vec!(edge(0, 0, "E")))); - assert_eq!(r.unwrap().as_slice(), + assert_eq!(r.unwrap(), r#"digraph single_cyclic_node { N0[label="N0"]; N0 -> N0[label="E"]; @@ -774,7 +774,7 @@ r#"digraph single_cyclic_node { "hasse_diagram", labels, vec!(edge(0, 1, ""), edge(0, 2, ""), edge(1, 3, ""), edge(2, 3, "")))); - assert_eq!(r.unwrap().as_slice(), + assert_eq!(r.unwrap(), r#"digraph hasse_diagram { N0[label="{x,y}"]; N1[label="{x}"]; @@ -812,7 +812,7 @@ r#"digraph hasse_diagram { render(&g, &mut writer).unwrap(); let r = (&mut writer.as_slice()).read_to_string(); - assert_eq!(r.unwrap().as_slice(), + assert_eq!(r.unwrap(), r#"digraph syntax_tree { N0[label="if test {\l branch1\l} else {\l branch2\l}\lafterward\l"]; N1[label="branch1"]; From 0ea31348d90d24c7a36d0543833b1174083bc7cb Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:21:31 -0500 Subject: [PATCH 08/35] liblog: remove unnecessary `as_slice` calls --- src/liblog/directive.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/liblog/directive.rs b/src/liblog/directive.rs index a93cf4c15682f..d1db0ec89a16b 100644 --- a/src/liblog/directive.rs +++ b/src/liblog/directive.rs @@ -100,7 +100,6 @@ mod tests { #[test] fn parse_logging_spec_valid() { let (dirs, filter) = parse_logging_spec("crate1::mod1=1,crate1::mod2,crate2=4"); - let dirs = dirs.as_slice(); assert_eq!(dirs.len(), 3); assert_eq!(dirs[0].name, Some("crate1::mod1".to_string())); assert_eq!(dirs[0].level, 1); @@ -117,7 +116,6 @@ mod tests { fn parse_logging_spec_invalid_crate() { // test parse_logging_spec with multiple = in specification let (dirs, filter) = parse_logging_spec("crate1::mod1=1=2,crate2=4"); - let dirs = dirs.as_slice(); assert_eq!(dirs.len(), 1); assert_eq!(dirs[0].name, Some("crate2".to_string())); assert_eq!(dirs[0].level, 4); @@ -128,7 +126,6 @@ mod tests { fn parse_logging_spec_invalid_log_level() { // test parse_logging_spec with 'noNumber' as log level let (dirs, filter) = parse_logging_spec("crate1::mod1=noNumber,crate2=4"); - let dirs = dirs.as_slice(); assert_eq!(dirs.len(), 1); assert_eq!(dirs[0].name, Some("crate2".to_string())); assert_eq!(dirs[0].level, 4); @@ -139,7 +136,6 @@ mod tests { fn parse_logging_spec_string_log_level() { // test parse_logging_spec with 'warn' as log level let (dirs, filter) = parse_logging_spec("crate1::mod1=wrong,crate2=warn"); - let dirs = dirs.as_slice(); assert_eq!(dirs.len(), 1); assert_eq!(dirs[0].name, Some("crate2".to_string())); assert_eq!(dirs[0].level, ::WARN); @@ -150,7 +146,6 @@ mod tests { fn parse_logging_spec_empty_log_level() { // test parse_logging_spec with '' as log level let (dirs, filter) = parse_logging_spec("crate1::mod1=wrong,crate2="); - let dirs = dirs.as_slice(); assert_eq!(dirs.len(), 1); assert_eq!(dirs[0].name, Some("crate2".to_string())); assert_eq!(dirs[0].level, ::MAX_LOG_LEVEL); @@ -161,7 +156,6 @@ mod tests { fn parse_logging_spec_global() { // test parse_logging_spec with no crate let (dirs, filter) = parse_logging_spec("warn,crate2=4"); - let dirs = dirs.as_slice(); assert_eq!(dirs.len(), 2); assert_eq!(dirs[0].name, None); assert_eq!(dirs[0].level, 2); @@ -173,7 +167,6 @@ mod tests { #[test] fn parse_logging_spec_valid_filter() { let (dirs, filter) = parse_logging_spec("crate1::mod1=1,crate1::mod2,crate2=4/abc"); - let dirs = dirs.as_slice(); assert_eq!(dirs.len(), 3); assert_eq!(dirs[0].name, Some("crate1::mod1".to_string())); assert_eq!(dirs[0].level, 1); @@ -183,26 +176,24 @@ mod tests { assert_eq!(dirs[2].name, Some("crate2".to_string())); assert_eq!(dirs[2].level, 4); - assert!(filter.is_some() && filter.unwrap().to_string().as_slice() == "abc"); + assert!(filter.is_some() && filter.unwrap().to_string() == "abc"); } #[test] fn parse_logging_spec_invalid_crate_filter() { let (dirs, filter) = parse_logging_spec("crate1::mod1=1=2,crate2=4/a.c"); - let dirs = dirs.as_slice(); assert_eq!(dirs.len(), 1); assert_eq!(dirs[0].name, Some("crate2".to_string())); assert_eq!(dirs[0].level, 4); - assert!(filter.is_some() && filter.unwrap().to_string().as_slice() == "a.c"); + assert!(filter.is_some() && filter.unwrap().to_string() == "a.c"); } #[test] fn parse_logging_spec_empty_with_filter() { let (dirs, filter) = parse_logging_spec("crate1/a*c"); - let dirs = dirs.as_slice(); assert_eq!(dirs.len(), 1); assert_eq!(dirs[0].name, Some("crate1".to_string())); assert_eq!(dirs[0].level, ::MAX_LOG_LEVEL); - assert!(filter.is_some() && filter.unwrap().to_string().as_slice() == "a*c"); + assert!(filter.is_some() && filter.unwrap().to_string() == "a*c"); } } From 89e6a81ef9831810a8e68189c6137040f76fb6b5 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:27:19 -0500 Subject: [PATCH 09/35] libregex: remove unnecessary `as_slice` calls --- src/libregex/parse.rs | 6 +++--- src/libregex/test/tests.rs | 10 +++++----- src/libregex/vm.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libregex/parse.rs b/src/libregex/parse.rs index 2bf3fa992cd66..5cd833e279791 100644 --- a/src/libregex/parse.rs +++ b/src/libregex/parse.rs @@ -523,11 +523,11 @@ impl<'a> Parser<'a> { // Parse the min and max values from the regex. let (mut min, mut max): (uint, Option); - if !inner.as_slice().contains(",") { + if !inner.contains(",") { min = try!(self.parse_uint(inner.as_slice())); max = Some(min); } else { - let pieces: Vec<&str> = inner.as_slice().splitn(1, ',').collect(); + let pieces: Vec<&str> = inner.splitn(1, ',').collect(); let (smin, smax) = (pieces[0], pieces[1]); if smin.len() == 0 { return self.err("Max repetitions cannot be specified \ @@ -751,7 +751,7 @@ impl<'a> Parser<'a> { return self.err("Capture names must have at least 1 character.") } let name = self.slice(self.chari, closer); - if !name.as_slice().chars().all(is_valid_cap) { + if !name.chars().all(is_valid_cap) { return self.err( "Capture names can only have underscores, letters and digits.") } diff --git a/src/libregex/test/tests.rs b/src/libregex/test/tests.rs index 2c59950abc3a3..27091b6ef4b4d 100644 --- a/src/libregex/test/tests.rs +++ b/src/libregex/test/tests.rs @@ -156,13 +156,13 @@ macro_rules! mat( }; // The test set sometimes leave out capture groups, so truncate // actual capture groups to match test set. - let (sexpect, mut sgot) = (expected.as_slice(), got.as_slice()); - if sgot.len() > sexpect.len() { - sgot = sgot[0..sexpect.len()] + let mut sgot = got.as_slice(); + if sgot.len() > expected.len() { + sgot = sgot[0..expected.len()] } - if sexpect != sgot { + if expected != sgot { panic!("For RE '{}' against '{}', expected '{}' but got '{}'", - $re, text, sexpect, sgot); + $re, text, expected, sgot); } } ); diff --git a/src/libregex/vm.rs b/src/libregex/vm.rs index 79019d213b8ba..4315c0f7b4040 100644 --- a/src/libregex/vm.rs +++ b/src/libregex/vm.rs @@ -147,7 +147,7 @@ impl<'r, 't> Nfa<'r, 't> { // jump ahead quickly. If it can't be found, then we can bail // out early. if self.prog.prefix.len() > 0 && clist.size == 0 { - let needle = self.prog.prefix.as_slice().as_bytes(); + let needle = self.prog.prefix.as_bytes(); let haystack = self.input.as_bytes()[self.ic..]; match find_prefix(needle, haystack) { None => break, From ae555a99a63fc3a6038a9bb4345a30413946aa8c Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:28:57 -0500 Subject: [PATCH 10/35] libregex_macros: remove unnecessary `as_slice` calls --- src/libregex_macros/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libregex_macros/lib.rs b/src/libregex_macros/lib.rs index 52ec18be97981..4df8819774319 100644 --- a/src/libregex_macros/lib.rs +++ b/src/libregex_macros/lib.rs @@ -115,7 +115,7 @@ impl<'a> NfaGen<'a> { // expression returned. let num_cap_locs = 2 * self.prog.num_captures(); let num_insts = self.prog.insts.len(); - let cap_names = self.vec_expr(self.names.as_slice().iter(), + let cap_names = self.vec_expr(self.names.iter(), |cx, name| match *name { Some(ref name) => { let name = name.as_slice(); @@ -125,14 +125,14 @@ impl<'a> NfaGen<'a> { } ); let prefix_anchor = - match self.prog.insts.as_slice()[1] { + match self.prog.insts[1] { EmptyBegin(flags) if flags & FLAG_MULTI == 0 => true, _ => false, }; let init_groups = self.vec_expr(range(0, num_cap_locs), |cx, _| cx.expr_none(self.sp)); - let prefix_lit = Rc::new(self.prog.prefix.as_slice().as_bytes().to_vec()); + let prefix_lit = Rc::new(self.prog.prefix.as_bytes().to_vec()); let prefix_bytes = self.cx.expr_lit(self.sp, ast::LitBinary(prefix_lit)); let check_prefix = self.check_prefix(); From 00f3c3f7a7058ac1b049810cffc2a8fa71ef7daa Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:53:34 -0500 Subject: [PATCH 11/35] librustc: remove unnecessary `as_slice()` calls --- src/librustc/lint/builtin.rs | 2 +- src/librustc/metadata/creader.rs | 4 ++-- src/librustc/metadata/cstore.rs | 3 +-- src/librustc/metadata/encoder.rs | 2 +- src/librustc/metadata/filesearch.rs | 2 +- src/librustc/metadata/loader.rs | 6 +++--- src/librustc/middle/borrowck/fragments.rs | 6 +++--- src/librustc/middle/cfg/graphviz.rs | 4 ++-- src/librustc/middle/dead.rs | 2 +- src/librustc/middle/liveness.rs | 4 ++-- src/librustc/middle/resolve.rs | 10 +++++----- src/librustc/middle/ty.rs | 10 +++++----- src/librustc/session/config.rs | 19 +++++++++---------- src/librustc/session/mod.rs | 2 +- src/librustc/util/ppaux.rs | 2 +- 15 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index b0ac98c94e748..c474820c3c934 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -902,7 +902,7 @@ impl NonSnakeCase { let mut buf = String::new(); if s.is_empty() { continue; } for ch in s.chars() { - if !buf.is_empty() && buf.as_slice() != "'" + if !buf.is_empty() && buf != "'" && ch.is_uppercase() && !last_upper { words.push(buf); diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 5a8d60fbecd6c..deeab18de7c13 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -277,7 +277,7 @@ fn visit_item(e: &Env, i: &ast::Item) { fn register_native_lib(sess: &Session, span: Option, name: String, kind: cstore::NativeLibaryKind) { - if name.as_slice().is_empty() { + if name.is_empty() { match span { Some(span) => { sess.span_err(span, "#[link(name = \"\")] given with \ @@ -304,7 +304,7 @@ fn existing_match(e: &Env, name: &str, hash: Option<&Svh>) -> Option { let mut ret = None; e.sess.cstore.iter_crate_data(|cnum, data| { - if data.name.as_slice() != name { return } + if data.name != name { return } match hash { Some(hash) if *hash == data.hash() => { ret = Some(cnum); return } diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index c844c8940fe62..07a8888c531cf 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -162,7 +162,7 @@ impl CStore { let mut ordering = Vec::new(); fn visit(cstore: &CStore, cnum: ast::CrateNum, ordering: &mut Vec) { - if ordering.as_slice().contains(&cnum) { return } + if ordering.contains(&cnum) { return } let meta = cstore.get_crate_data(cnum); for (_, &dep) in meta.cnum_map.iter() { visit(cstore, dep, ordering); @@ -173,7 +173,6 @@ impl CStore { visit(self, num, &mut ordering); } ordering.as_mut_slice().reverse(); - let ordering = ordering.as_slice(); let mut libs = self.used_crate_sources.borrow() .iter() .map(|src| (src.cnum, match prefer { diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index f7ee9fa65229c..3a111a3223b68 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -474,7 +474,7 @@ fn encode_reexported_static_methods(ecx: &EncodeContext, // encoded metadata for static methods relative to Bar, // but not yet for Foo. // - if path_differs || original_name.get() != exp.name.as_slice() { + if path_differs || original_name.get() != exp.name { if !encode_reexported_static_base_methods(ecx, rbml_w, exp) { if encode_reexported_static_trait_methods(ecx, rbml_w, exp) { debug!("(encode reexported static methods) {} [trait]", diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 89f3343ef123a..63fc2af492cb0 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -214,7 +214,7 @@ pub fn rust_path() -> Vec { let mut env_rust_path: Vec = match get_rust_path() { Some(env_path) => { let env_path_components = - env_path.as_slice().split_str(PATH_ENTRY_SEPARATOR); + env_path.split_str(PATH_ENTRY_SEPARATOR); env_path_components.map(|s| Path::new(s)).collect() } None => Vec::new() diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index bd0446dd67ff2..14b1eea2eb819 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -545,7 +545,7 @@ impl<'a> Context<'a> { fn crate_matches(&mut self, crate_data: &[u8], libpath: &Path) -> bool { if self.should_match_name { match decoder::maybe_get_crate_name(crate_data) { - Some(ref name) if self.crate_name == name.as_slice() => {} + Some(ref name) if self.crate_name == *name => {} _ => { info!("Rejecting via crate name"); return false } } } @@ -560,7 +560,7 @@ impl<'a> Context<'a> { None => { debug!("triple not present"); return false } Some(t) => t, }; - if triple.as_slice() != self.triple { + if triple != self.triple { info!("Rejecting via crate triple: expected {} got {}", self.triple, triple); self.rejected_via_triple.push(CrateMismatch { path: libpath.clone(), @@ -743,7 +743,7 @@ fn get_metadata_section_imp(is_osx: bool, filename: &Path) -> Result(this: &MoveData<'tcx>, tcx: &ty::ctxt<'tcx>) { debug!("fragments 3 assigned: {}", path_lps(assigned.as_slice())); // Fourth, build the leftover from the moved, assigned, and parents. - for m in moved.as_slice().iter() { + for m in moved.iter() { let lp = this.path_loan_path(*m); add_fragment_siblings(this, tcx, &mut unmoved, lp, None); } - for a in assigned.as_slice().iter() { + for a in assigned.iter() { let lp = this.path_loan_path(*a); add_fragment_siblings(this, tcx, &mut unmoved, lp, None); } - for p in parents.as_slice().iter() { + for p in parents.iter() { let lp = this.path_loan_path(*p); add_fragment_siblings(this, tcx, &mut unmoved, lp, None); } diff --git a/src/librustc/middle/cfg/graphviz.rs b/src/librustc/middle/cfg/graphviz.rs index 92c87aacc7dc5..e33f44967f1ad 100644 --- a/src/librustc/middle/cfg/graphviz.rs +++ b/src/librustc/middle/cfg/graphviz.rs @@ -31,14 +31,14 @@ pub struct LabelledCFG<'a, 'ast: 'a> { fn replace_newline_with_backslash_l(s: String) -> String { // Replacing newlines with \\l causes each line to be left-aligned, // improving presentation of (long) pretty-printed expressions. - if s.as_slice().contains("\n") { + if s.contains("\n") { let mut s = s.replace("\n", "\\l"); // Apparently left-alignment applies to the line that precedes // \l, not the line that follows; so, add \l at end of string // if not already present, ensuring last line gets left-aligned // as well. let mut last_two: Vec<_> = - s.as_slice().chars().rev().take(2).collect(); + s.chars().rev().take(2).collect(); last_two.reverse(); if last_two != ['\\', 'l'] { s.push_str("\\l"); diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 03fe878242159..d2f43faa00355 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -321,7 +321,7 @@ fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool { for attr in lint::gather_attrs(attrs).into_iter() { match attr { Ok((ref name, lint::Allow, _)) - if name.get() == dead_code.as_slice() => return true, + if name.get() == dead_code => return true, _ => (), } } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 523c9f3330968..a6d3c15df8a74 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1065,7 +1065,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // the same bindings, and we also consider the first pattern to be // the "authoritative" set of ids let arm_succ = - self.define_bindings_in_arm_pats(arm.pats.as_slice().head().map(|p| &**p), + self.define_bindings_in_arm_pats(arm.pats.head().map(|p| &**p), guard_succ); self.merge_from_succ(ln, arm_succ, first_merge); first_merge = false; @@ -1431,7 +1431,7 @@ fn check_arm(this: &mut Liveness, arm: &ast::Arm) { // only consider the first pattern; any later patterns must have // the same bindings, and we also consider the first pattern to be // the "authoritative" set of ids - this.arm_pats_bindings(arm.pats.as_slice().head().map(|p| &**p), |this, ln, var, sp, id| { + this.arm_pats_bindings(arm.pats.head().map(|p| &**p), |this, ln, var, sp, id| { this.warn_about_unused(sp, id, ln, var); }); visit::walk_arm(this, arm); diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index b958bdce0a7e8..66acda7824607 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1668,7 +1668,7 @@ impl<'a> Resolver<'a> { let module_path = match view_path.node { ViewPathSimple(_, ref full_path, _) => { full_path.segments - .as_slice().init() + .init() .iter().map(|ident| ident.identifier.name) .collect() } @@ -1739,7 +1739,7 @@ impl<'a> Resolver<'a> { continue; } }; - let module_path = module_path.as_slice().init(); + let module_path = module_path.init(); (module_path.to_vec(), name) } }; @@ -3735,12 +3735,12 @@ impl<'a> Resolver<'a> { .codemap() .span_to_snippet((*imports)[index].span) .unwrap(); - if sn.as_slice().contains("::") { + if sn.contains("::") { self.resolve_error((*imports)[index].span, "unresolved import"); } else { let err = format!("unresolved import (maybe you meant `{}::*`?)", - sn.as_slice().slice(0, sn.len())); + sn.slice(0, sn.len())); self.resolve_error((*imports)[index].span, err.as_slice()); } } @@ -5748,7 +5748,7 @@ impl<'a> Resolver<'a> { }); if method_scope && token::get_name(self.self_name).get() - == wrong_name.as_slice() { + == wrong_name { self.resolve_error( expr.span, "`self` is not available \ diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 994f0c2090a57..8a2529701bbb3 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2907,7 +2907,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents { res = res | TC::ReachesFfiUnsafe; } - match repr_hints.as_slice().get(0) { + match repr_hints.get(0) { Some(h) => if !h.is_ffi_safe() { res = res | TC::ReachesFfiUnsafe; }, @@ -3566,23 +3566,23 @@ pub fn positional_element_ty<'tcx>(cx: &ctxt<'tcx>, variant: Option) -> Option> { match (&ty.sty, variant) { - (&ty_tup(ref v), None) => v.as_slice().get(i).map(|&t| t), + (&ty_tup(ref v), None) => v.get(i).map(|&t| t), (&ty_struct(def_id, ref substs), None) => lookup_struct_fields(cx, def_id) - .as_slice().get(i) + .get(i) .map(|&t|lookup_item_type(cx, t.id).ty.subst(cx, substs)), (&ty_enum(def_id, ref substs), Some(variant_def_id)) => { let variant_info = enum_variant_with_id(cx, def_id, variant_def_id); - variant_info.args.as_slice().get(i).map(|t|t.subst(cx, substs)) + variant_info.args.get(i).map(|t|t.subst(cx, substs)) } (&ty_enum(def_id, ref substs), None) => { assert!(enum_is_univariant(cx, def_id)); let enum_variants = enum_variants(cx, def_id); let variant_info = &(*enum_variants)[0]; - variant_info.args.as_slice().get(i).map(|t|t.subst(cx, substs)) + variant_info.args.get(i).map(|t|t.subst(cx, substs)) } _ => None diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index cbc9dd9145bfb..8701248d1f58e 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -512,13 +512,13 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions { let mut cg = basic_codegen_options(); for option in matches.opt_strs("C").into_iter() { - let mut iter = option.as_slice().splitn(1, '='); + let mut iter = option.splitn(1, '='); let key = iter.next().unwrap(); let value = iter.next(); let option_to_lookup = key.replace("-", "_"); let mut found = false; for &(candidate, setter, opt_type_desc, _) in CG_OPTIONS.iter() { - if option_to_lookup.as_slice() != candidate { continue } + if option_to_lookup != candidate { continue } if !setter(&mut cg, value) { match (value, opt_type_desc) { (Some(..), None) => { @@ -714,7 +714,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { for &level in [lint::Allow, lint::Warn, lint::Deny, lint::Forbid].iter() { for lint_name in matches.opt_strs(level.as_str()).into_iter() { - if lint_name.as_slice() == "help" { + if lint_name == "help" { describe_lints = true; } else { lint_opts.push((lint_name.replace("-", "_").into_string(), level)); @@ -727,9 +727,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let debug_map = debugging_opts_map(); for debug_flag in debug_flags.iter() { let mut this_bit = 0; - for tuple in debug_map.iter() { - let (name, bit) = match *tuple { (ref a, _, b) => (a, b) }; - if *name == debug_flag.as_slice() { + for &(name, _, bit) in debug_map.iter() { + if name == *debug_flag { this_bit = bit; break; } @@ -749,7 +748,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { if !parse_only && !no_trans { let unparsed_output_types = matches.opt_strs("emit"); for unparsed_output_type in unparsed_output_types.iter() { - for part in unparsed_output_type.as_slice().split(',') { + for part in unparsed_output_type.split(',') { let output_type = match part.as_slice() { "asm" => OutputTypeAssembly, "ir" => OutputTypeLlvmAssembly, @@ -824,7 +823,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { }).collect(); let libs = matches.opt_strs("l").into_iter().map(|s| { - let mut parts = s.as_slice().rsplitn(1, ':'); + let mut parts = s.rsplitn(1, ':'); let kind = parts.next().unwrap(); let (name, kind) = match (parts.next(), kind) { (None, name) | @@ -875,7 +874,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let mut externs = HashMap::new(); for arg in matches.opt_strs("extern").iter() { - let mut parts = arg.as_slice().splitn(1, '='); + let mut parts = arg.splitn(1, '='); let name = match parts.next() { Some(s) => s, None => early_error("--extern value must not be empty"), @@ -925,7 +924,7 @@ pub fn parse_crate_types_from_list(list_list: Vec) -> Result = Vec::new(); for unparsed_crate_type in list_list.iter() { - for part in unparsed_crate_type.as_slice().split(',') { + for part in unparsed_crate_type.split(',') { let new_part = match part { "lib" => default_lib_output(), "rlib" => CrateTypeRlib, diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 047e5985569ae..e4d34e09d330a 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -257,7 +257,7 @@ pub fn build_session_(sopts: config::Options, let can_print_warnings = sopts.lint_opts .iter() - .filter(|&&(ref key, _)| key.as_slice() == "warnings") + .filter(|&&(ref key, _)| *key == "warnings") .map(|&(_, ref level)| *level != lint::Allow) .last() .unwrap_or(true); diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 1283e89c29d0c..3895a11372674 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -538,7 +538,7 @@ pub fn parameterized<'tcx>(cx: &ctxt<'tcx>, pub fn ty_to_short_str<'tcx>(cx: &ctxt<'tcx>, typ: Ty<'tcx>) -> String { let mut s = typ.repr(cx).to_string(); if s.len() >= 32u { - s = s.as_slice().slice(0u, 32u).to_string(); + s = s.slice(0u, 32u).to_string(); } return s; } From 7d8eabb226718ac70531571478b27a1c9fd74e83 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 13:57:31 -0500 Subject: [PATCH 12/35] librustc_back: remove unnecessary `as_slice()` calls --- src/librustc_back/arm.rs | 2 +- src/librustc_back/rpath.rs | 24 ++++++++++++------------ src/librustc_back/sha2.rs | 3 +-- src/librustc_back/target/mod.rs | 3 +-- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/librustc_back/arm.rs b/src/librustc_back/arm.rs index 134f7105ea76e..ea4d5c820f8b8 100644 --- a/src/librustc_back/arm.rs +++ b/src/librustc_back/arm.rs @@ -12,7 +12,7 @@ use target_strs; use syntax::abi; pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t { - let cc_args = if target_triple.as_slice().contains("thumb") { + let cc_args = if target_triple.contains("thumb") { vec!("-mthumb".to_string()) } else { vec!("-marm".to_string()) diff --git a/src/librustc_back/rpath.rs b/src/librustc_back/rpath.rs index 9c94823f86758..ea691b85f6c27 100644 --- a/src/librustc_back/rpath.rs +++ b/src/librustc_back/rpath.rs @@ -156,9 +156,9 @@ mod test { "rpath2".to_string(), "rpath1".to_string() ]); - assert!(res.as_slice() == [ - "rpath1".to_string(), - "rpath2".to_string() + assert!(res == [ + "rpath1", + "rpath2", ]); } @@ -176,11 +176,11 @@ mod test { "4a".to_string(), "3".to_string() ]); - assert!(res.as_slice() == [ - "1a".to_string(), - "2".to_string(), - "4a".to_string(), - "3".to_string() + assert!(res == [ + "1a", + "2", + "4a", + "3", ]); } @@ -196,7 +196,7 @@ mod test { realpath: |p| Ok(p.clone()) }; let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); - assert_eq!(res.as_slice(), "$ORIGIN/../lib"); + assert_eq!(res, "$ORIGIN/../lib"); } #[test] @@ -211,7 +211,7 @@ mod test { realpath: |p| Ok(p.clone()) }; let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); - assert_eq!(res.as_slice(), "$ORIGIN/../lib"); + assert_eq!(res, "$ORIGIN/../lib"); } #[test] @@ -226,7 +226,7 @@ mod test { realpath: |p| Ok(p.clone()) }; let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); - assert_eq!(res.as_slice(), "$ORIGIN/../lib"); + assert_eq!(res, "$ORIGIN/../lib"); } #[test] @@ -241,6 +241,6 @@ mod test { realpath: |p| Ok(p.clone()) }; let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); - assert_eq!(res.as_slice(), "@loader_path/../lib"); + assert_eq!(res, "@loader_path/../lib"); } } diff --git a/src/librustc_back/sha2.rs b/src/librustc_back/sha2.rs index 4c08c82ecac5a..1b662ef178760 100644 --- a/src/librustc_back/sha2.rs +++ b/src/librustc_back/sha2.rs @@ -263,7 +263,7 @@ pub trait Digest { /// Convenience function that retrieves the result of a digest as a /// String in hexadecimal format. fn result_str(&mut self) -> String { - self.result_bytes().as_slice().to_hex().to_string() + self.result_bytes().to_hex().to_string() } } @@ -568,7 +568,6 @@ mod tests { while left > 0u { let take = (left + 1u) / 2u; sh.input_str(t.input - .as_slice() .slice(len - left, take + len - left)); left = left - take; } diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 68a80edc5d07f..76adc4e472f82 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -200,7 +200,7 @@ impl Target { pub fn adjust_abi(&self, abi: abi::Abi) -> abi::Abi { match abi { abi::System => { - if self.options.is_like_windows && self.arch.as_slice() == "x86" { + if self.options.is_like_windows && self.arch == "x86" { abi::Stdcall } else { abi::C @@ -308,7 +308,6 @@ impl Target { ( $($name:ident),+ ) => ( { let target = target.replace("-", "_"); - let target = target.as_slice(); if false { } $( else if target == stringify!($name) { From 8bb5ef9df5aeb7e46a9ad9350aaf9086d05f0556 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 14:10:25 -0500 Subject: [PATCH 13/35] librustc_trans: remove unnecessary `as_slice` calls --- src/librustc_driver/lib.rs | 4 ++-- src/librustc_trans/back/link.rs | 14 +++++++------- src/librustc_trans/back/lto.rs | 2 +- src/librustc_trans/back/write.rs | 6 +++--- src/librustc_trans/save/recorder.rs | 2 +- src/librustc_trans/trans/asm.rs | 2 +- src/librustc_trans/trans/base.rs | 2 +- src/librustc_trans/trans/builder.rs | 2 +- src/librustc_trans/trans/context.rs | 2 -- src/librustc_trans/trans/debuginfo.rs | 24 ++++++++++++------------ src/librustc_trans/trans/glue.rs | 2 +- 11 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 33c009cf3291b..7f15f5e87d9dd 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -378,13 +378,13 @@ pub fn handle_options(mut args: Vec) -> Option { // Don't handle -W help here, because we might first load plugins. let r = matches.opt_strs("Z"); - if r.iter().any(|x| x.as_slice() == "help") { + if r.iter().any(|x| *x == "help") { describe_debug_flags(); return None; } let cg_flags = matches.opt_strs("C"); - if cg_flags.iter().any(|x| x.as_slice() == "help") { + if cg_flags.iter().any(|x| *x == "help") { describe_codegen_flags(); return None; } diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 6057f9d908190..62f8177ed758d 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -140,7 +140,7 @@ pub fn find_crate_name(sess: Option<&Session>, if let Some(sess) = sess { if let Some(ref s) = sess.opts.crate_name { if let Some((attr, ref name)) = attr_crate_name { - if s.as_slice() != name.get() { + if *s != name.get() { let msg = format!("--crate-name and #[crate_name] are \ required to match, but `{}` != `{}`", s, name); @@ -249,7 +249,7 @@ pub fn sanitize(s: &str) -> String { let mut tstr = String::new(); for c in c.escape_unicode() { tstr.push(c) } result.push('$'); - result.push_str(tstr.as_slice().slice_from(1)); + result.push_str(tstr.slice_from(1)); } } } @@ -669,7 +669,7 @@ fn link_rlib<'a>(sess: &'a Session, fn write_rlib_bytecode_object_v1(writer: &mut T, bc_data_deflated: &[u8]) -> ::std::io::IoResult<()> { - let bc_data_deflated_size: u64 = bc_data_deflated.as_slice().len() as u64; + let bc_data_deflated_size: u64 = bc_data_deflated.len() as u64; try! { writer.write(RLIB_BYTECODE_OBJECT_MAGIC) }; try! { writer.write_le_u32(1) }; @@ -910,10 +910,10 @@ fn link_args(cmd: &mut Command, let args = sess.opts.cg.link_args.as_ref().unwrap_or(&empty_vec); let mut args = args.iter().chain(used_link_args.iter()); if !dylib - && (t.options.relocation_model.as_slice() == "pic" - || sess.opts.cg.relocation_model.as_ref() - .unwrap_or(&empty_str).as_slice() == "pic") - && !args.any(|x| x.as_slice() == "-static") { + && (t.options.relocation_model == "pic" + || *sess.opts.cg.relocation_model.as_ref() + .unwrap_or(&empty_str) == "pic") + && !args.any(|x| *x == "-static") { cmd.arg("-pie"); } } diff --git a/src/librustc_trans/back/lto.rs b/src/librustc_trans/back/lto.rs index 407f632bee7dd..a715849ddf62f 100644 --- a/src/librustc_trans/back/lto.rs +++ b/src/librustc_trans/back/lto.rs @@ -143,7 +143,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef, // Internalize everything but the reachable symbols of the current module let cstrs: Vec<::std::c_str::CString> = - reachable.iter().map(|s| s.as_slice().to_c_str()).collect(); + reachable.iter().map(|s| s.to_c_str()).collect(); let arr: Vec<*const i8> = cstrs.iter().map(|c| c.as_ptr()).collect(); let ptr = arr.as_ptr(); unsafe { diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index e5ffe2675d6f4..a919fe686abfc 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -363,7 +363,7 @@ unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef, user: *mut c_vo let pass_name = pass_name.as_str().expect("got a non-UTF8 pass name from LLVM"); let enabled = match cgcx.remark { AllPasses => true, - SomePasses(ref v) => v.iter().any(|s| s.as_slice() == pass_name), + SomePasses(ref v) => v.iter().any(|s| *s == pass_name), }; if enabled { @@ -421,7 +421,7 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext, // If we're verifying or linting, add them to the function pass // manager. let addpass = |pass: &str| { - pass.as_slice().with_c_str(|s| llvm::LLVMRustAddPass(fpm, s)) + pass.with_c_str(|s| llvm::LLVMRustAddPass(fpm, s)) }; if !config.no_verify { assert!(addpass("verify")); } @@ -433,7 +433,7 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext, } for pass in config.passes.iter() { - pass.as_slice().with_c_str(|s| { + pass.with_c_str(|s| { if !llvm::LLVMRustAddPass(mpm, s) { cgcx.handler.warn(format!("unknown pass {}, ignoring", *pass).as_slice()); diff --git a/src/librustc_trans/save/recorder.rs b/src/librustc_trans/save/recorder.rs index 2102133f97d3d..f0bb441145cc2 100644 --- a/src/librustc_trans/save/recorder.rs +++ b/src/librustc_trans/save/recorder.rs @@ -163,7 +163,7 @@ impl<'a> FmtStrs<'a> { let values = values.iter().map(|s| { // Never take more than 1020 chars if s.len() > 1020 { - s.as_slice().slice_to(1020) + s.slice_to(1020) } else { s.as_slice() } diff --git a/src/librustc_trans/trans/asm.rs b/src/librustc_trans/trans/asm.rs index 77102d2db39bb..e3afe22897e39 100644 --- a/src/librustc_trans/trans/asm.rs +++ b/src/librustc_trans/trans/asm.rs @@ -122,7 +122,7 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm) }; let r = ia.asm.get().with_c_str(|a| { - constraints.as_slice().with_c_str(|c| { + constraints.with_c_str(|c| { InlineAsmCall(bcx, a, c, diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 9d0e096c71d64..3090119788c32 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -2739,7 +2739,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { format!("Illegal null byte in export_name \ value: `{}`", sym).as_slice()); } - let g = sym.as_slice().with_c_str(|buf| { + let g = sym.with_c_str(|buf| { llvm::LLVMAddGlobal(ccx.llmod(), llty, buf) }); diff --git a/src/librustc_trans/trans/builder.rs b/src/librustc_trans/trans/builder.rs index 526592181ae64..cf940b1384671 100644 --- a/src/librustc_trans/trans/builder.rs +++ b/src/librustc_trans/trans/builder.rs @@ -774,7 +774,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let comment_text = format!("{} {}", "#", sanitized.replace("\n", "\n\t# ")); self.count_insn("inlineasm"); - let asm = comment_text.as_slice().with_c_str(|c| { + let asm = comment_text.with_c_str(|c| { unsafe { llvm::LLVMConstInlineAsm(Type::func(&[], &Type::void(self.ccx)).to_ref(), c, noname(), False, False) diff --git a/src/librustc_trans/trans/context.rs b/src/librustc_trans/trans/context.rs index fd9d6b8f2c3b2..3b5197594a128 100644 --- a/src/librustc_trans/trans/context.rs +++ b/src/librustc_trans/trans/context.rs @@ -222,14 +222,12 @@ unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextR sess.target .target .data_layout - .as_slice() .with_c_str(|buf| { llvm::LLVMSetDataLayout(llmod, buf); }); sess.target .target .llvm_target - .as_slice() .with_c_str(|buf| { llvm::LLVMRustSetNormalizedTarget(llmod, buf); }); diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 555cb0004892f..6c75086fec60b 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -824,8 +824,8 @@ pub fn create_global_var_metadata(cx: &CrateContext, namespace_node.mangled_name_of_contained_item(var_name.as_slice()); let var_scope = namespace_node.scope; - var_name.as_slice().with_c_str(|var_name| { - linkage_name.as_slice().with_c_str(|linkage_name| { + var_name.with_c_str(|var_name| { + linkage_name.with_c_str(|linkage_name| { unsafe { llvm::LLVMDIBuilderCreateStaticVariable(DIB(cx), var_scope, @@ -1323,7 +1323,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, let containing_scope = namespace_node.scope; (linkage_name, containing_scope) } else { - (function_name.as_slice().to_string(), file_metadata) + (function_name.clone(), file_metadata) }; // Clang sets this parameter to the opening brace of the function's block, @@ -1332,8 +1332,8 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, let is_local_to_unit = is_node_local_to_unit(cx, fn_ast_id); - let fn_metadata = function_name.as_slice().with_c_str(|function_name| { - linkage_name.as_slice().with_c_str(|linkage_name| { + let fn_metadata = function_name.with_c_str(|function_name| { + linkage_name.with_c_str(|linkage_name| { unsafe { llvm::LLVMDIBuilderCreateFunction( DIB(cx), @@ -1554,7 +1554,7 @@ fn compile_unit_metadata(cx: &CrateContext) { path_bytes.insert(1, prefix[1]); } - path_bytes.as_slice().to_c_str() + path_bytes.to_c_str() } _ => fallback_path(cx) } @@ -1589,7 +1589,7 @@ fn compile_unit_metadata(cx: &CrateContext) { }); fn fallback_path(cx: &CrateContext) -> CString { - cx.link_meta().crate_name.as_slice().to_c_str() + cx.link_meta().crate_name.to_c_str() } } @@ -1796,7 +1796,7 @@ fn pointer_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, let pointer_llvm_type = type_of::type_of(cx, pointer_type); let (pointer_size, pointer_align) = size_and_align_of(cx, pointer_llvm_type); let name = compute_debuginfo_type_name(cx, pointer_type, false); - let ptr_metadata = name.as_slice().with_c_str(|name| { + let ptr_metadata = name.with_c_str(|name| { unsafe { llvm::LLVMDIBuilderCreatePointerType( DIB(cx), @@ -2488,8 +2488,8 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, .borrow() .get_unique_type_id_as_string(unique_type_id); - let enum_metadata = enum_name.as_slice().with_c_str(|enum_name| { - unique_type_id_str.as_slice().with_c_str(|unique_type_id_str| { + let enum_metadata = enum_name.with_c_str(|enum_name| { + unique_type_id_str.with_c_str(|unique_type_id_str| { unsafe { llvm::LLVMDIBuilderCreateUnionType( DIB(cx), @@ -2616,7 +2616,7 @@ fn set_members_of_composite_type(cx: &CrateContext, ComputedMemberOffset => machine::llelement_offset(cx, composite_llvm_type, i) }; - member_description.name.as_slice().with_c_str(|member_name| { + member_description.name.with_c_str(|member_name| { unsafe { llvm::LLVMDIBuilderCreateMemberType( DIB(cx), @@ -2656,7 +2656,7 @@ fn create_struct_stub(cx: &CrateContext, .get_unique_type_id_as_string(unique_type_id); let metadata_stub = unsafe { struct_type_name.with_c_str(|name| { - unique_type_id_str.as_slice().with_c_str(|unique_type_id| { + unique_type_id_str.with_c_str(|unique_type_id| { // LLVMDIBuilderCreateStructType() wants an empty array. A null // pointer will lead to hard to trace and debug LLVM assertions // later on in llvm/lib/IR/Value.cpp. diff --git a/src/librustc_trans/trans/glue.rs b/src/librustc_trans/trans/glue.rs index fbaf1e6581060..4575d8a41e52a 100644 --- a/src/librustc_trans/trans/glue.rs +++ b/src/librustc_trans/trans/glue.rs @@ -496,7 +496,7 @@ pub fn declare_tydesc<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) let llalign = llalign_of(ccx, llty); let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc"); debug!("+++ declare_tydesc {} {}", ppaux::ty_to_string(ccx.tcx(), t), name); - let gvar = name.as_slice().with_c_str(|buf| { + let gvar = name.with_c_str(|buf| { unsafe { llvm::LLVMAddGlobal(ccx.llmod(), ccx.tydesc_type().to_ref(), buf) } From e6bd217ce8cf3384bdf47b63833a8b04e40e0753 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 14:19:27 -0500 Subject: [PATCH 14/35] librustdoc: remove unnecessary `as_slice()` calls --- src/librustdoc/clean/inline.rs | 4 ++-- src/librustdoc/clean/mod.rs | 10 +++++----- src/librustdoc/html/format.rs | 6 +++--- src/librustdoc/html/markdown.rs | 4 ++-- src/librustdoc/html/render.rs | 22 +++++++++++----------- src/librustdoc/lib.rs | 16 ++++++++-------- src/librustdoc/passes.rs | 16 ++++++++-------- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 1f30dc9040d52..3ee07df6ed447 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -341,10 +341,10 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt, fn is_doc_hidden(a: &clean::Attribute) -> bool { match *a { - clean::List(ref name, ref inner) if name.as_slice() == "doc" => { + clean::List(ref name, ref inner) if *name == "doc" => { inner.iter().any(|a| { match *a { - clean::Word(ref s) => s.as_slice() == "hidden", + clean::Word(ref s) => *s == "hidden", _ => false, } }) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7e02891160ad2..bc870d39c5d7f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -256,7 +256,7 @@ impl Item { pub fn doc_list<'a>(&'a self) -> Option<&'a [Attribute]> { for attr in self.attrs.iter() { match *attr { - List(ref x, ref list) if "doc" == x.as_slice() => { + List(ref x, ref list) if "doc" == *x => { return Some(list.as_slice()); } _ => {} @@ -270,7 +270,7 @@ impl Item { pub fn doc_value<'a>(&'a self) -> Option<&'a str> { for attr in self.attrs.iter() { match *attr { - NameValue(ref x, ref v) if "doc" == x.as_slice() => { + NameValue(ref x, ref v) if "doc" == *x => { return Some(v.as_slice()); } _ => {} @@ -284,7 +284,7 @@ impl Item { Some(ref l) => { for innerattr in l.iter() { match *innerattr { - Word(ref s) if "hidden" == s.as_slice() => { + Word(ref s) if "hidden" == *s => { return true } _ => (), @@ -1217,13 +1217,13 @@ impl PrimitiveType { fn find(attrs: &[Attribute]) -> Option { for attr in attrs.iter() { let list = match *attr { - List(ref k, ref l) if k.as_slice() == "doc" => l, + List(ref k, ref l) if *k == "doc" => l, _ => continue, }; for sub_attr in list.iter() { let value = match *sub_attr { NameValue(ref k, ref v) - if k.as_slice() == "primitive" => v.as_slice(), + if *k == "primitive" => v.as_slice(), _ => continue, }; match PrimitiveType::from_str(value) { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 9861d18ce51f0..0fca59962d40c 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -251,8 +251,8 @@ fn path(w: &mut fmt::Formatter, path: &clean::Path, print_all: bool, Some(root) => { let mut root = String::from_str(root.as_slice()); for seg in path.segments[..amt].iter() { - if "super" == seg.name.as_slice() || - "self" == seg.name.as_slice() { + if "super" == seg.name || + "self" == seg.name { try!(write!(w, "{}::", seg.name)); } else { root.push_str(seg.name.as_slice()); @@ -337,7 +337,7 @@ fn primitive_link(f: &mut fmt::Formatter, Some(root) => { try!(write!(f, "", root, - path.ref0().as_slice().head().unwrap(), + path.ref0().head().unwrap(), prim.to_url_str())); needs_termination = true; } diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index df25daa3ca1ac..10563c61e1465 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -231,7 +231,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result { }; // Transform the contents of the header into a hyphenated string - let id = s.as_slice().words().map(|s| s.to_ascii_lower()) + let id = s.words().map(|s| s.to_ascii_lower()) .collect::>().connect("-"); // This is a terrible hack working around how hoedown gives us rendered @@ -393,7 +393,7 @@ impl LangString { let mut seen_other_tags = false; let mut data = LangString::all_false(); - let mut tokens = string.as_slice().split(|c: char| + let mut tokens = string.split(|c: char| !(c == '_' || c == '-' || c.is_alphanumeric()) ); diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 9eee8e04f0c2b..79ab452dba626 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -277,15 +277,15 @@ pub fn run(mut krate: clean::Crate, for attr in attrs.iter() { match *attr { clean::NameValue(ref x, ref s) - if "html_favicon_url" == x.as_slice() => { + if "html_favicon_url" == *x => { cx.layout.favicon = s.to_string(); } clean::NameValue(ref x, ref s) - if "html_logo_url" == x.as_slice() => { + if "html_logo_url" == *x => { cx.layout.logo = s.to_string(); } clean::NameValue(ref x, ref s) - if "html_playground_url" == x.as_slice() => { + if "html_playground_url" == *x => { cx.layout.playground_url = s.to_string(); markdown::PLAYGROUND_KRATE.with(|slot| { if slot.borrow().is_none() { @@ -295,7 +295,7 @@ pub fn run(mut krate: clean::Crate, }); } clean::Word(ref x) - if "html_no_source" == x.as_slice() => { + if "html_no_source" == *x => { cx.include_sources = false; } _ => {} @@ -434,7 +434,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::IoResult for (i, item) in cache.search_index.iter().enumerate() { // Omit the path if it is same to that of the prior item. let path; - if lastpath.as_slice() == item.path.as_slice() { + if lastpath == item.path { path = ""; } else { lastpath = item.path.to_string(); @@ -513,10 +513,10 @@ fn write_shared(cx: &Context, if path.exists() { for line in BufferedReader::new(File::open(path)).lines() { let line = try!(line); - if !line.as_slice().starts_with(key) { + if !line.starts_with(key) { continue } - if line.as_slice().starts_with( + if line.starts_with( format!("{}['{}']", key, krate).as_slice()) { continue } @@ -670,12 +670,12 @@ fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation { // external crate for attr in e.attrs.iter() { match *attr { - clean::List(ref x, ref list) if "doc" == x.as_slice() => { + clean::List(ref x, ref list) if "doc" == *x => { for attr in list.iter() { match *attr { clean::NameValue(ref x, ref s) - if "html_root_url" == x.as_slice() => { - if s.as_slice().ends_with("/") { + if "html_root_url" == *x => { + if s.ends_with("/") { return Remote(s.to_string()); } return Remote(format!("{}/", s)); @@ -964,7 +964,7 @@ impl DocFolder for Cache { let dox = match attrs.into_iter().find(|a| { match *a { clean::NameValue(ref x, _) - if "doc" == x.as_slice() => { + if "doc" == *x => { true } _ => false diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 66108bea9885c..6d9e8dc722f8a 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -299,7 +299,7 @@ fn acquire_input(input: &str, fn parse_externs(matches: &getopts::Matches) -> Result { let mut externs = HashMap::new(); for arg in matches.opt_strs("extern").iter() { - let mut parts = arg.as_slice().splitn(1, '='); + let mut parts = arg.splitn(1, '='); let name = match parts.next() { Some(s) => s, None => { @@ -363,18 +363,18 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche for inner in nested.iter() { match *inner { clean::Word(ref x) - if "no_default_passes" == x.as_slice() => { + if "no_default_passes" == *x => { default_passes = false; } clean::NameValue(ref x, ref value) - if "passes" == x.as_slice() => { - for pass in value.as_slice().words() { + if "passes" == *x => { + for pass in value.words() { passes.push(pass.to_string()); } } clean::NameValue(ref x, ref value) - if "plugins" == x.as_slice() => { - for p in value.as_slice().words() { + if "plugins" == *x => { + for p in value.words() { plugins.push(p.to_string()); } } @@ -397,7 +397,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche for pass in passes.iter() { let plugin = match PASSES.iter() .position(|&(p, _, _)| { - p == pass.as_slice() + p == *pass }) { Some(i) => PASSES[i].val1(), None => { @@ -434,7 +434,7 @@ fn json_input(input: &str) -> Result { // Make sure the schema is what we expect match obj.remove(&"schema".to_string()) { Some(Json::String(version)) => { - if version.as_slice() != SCHEMA_VERSION { + if version != SCHEMA_VERSION { return Err(format!( "sorry, but I only understand version {}", SCHEMA_VERSION)) diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 8675d2b3749cd..e368d7f93320c 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -258,7 +258,7 @@ pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult { for attr in i.attrs.iter() { match attr { &clean::NameValue(ref x, ref s) - if "doc" == x.as_slice() => { + if "doc" == *x => { avec.push(clean::NameValue("doc".to_string(), unindent(s.as_slice()))) } @@ -283,7 +283,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult { for attr in i.attrs.iter() { match *attr { clean::NameValue(ref x, ref s) - if "doc" == x.as_slice() => { + if "doc" == *x => { docstr.push_str(s.as_slice()); docstr.push('\n'); }, @@ -291,7 +291,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult { } } let mut a: Vec = i.attrs.iter().filter(|&a| match a { - &clean::NameValue(ref x, _) if "doc" == x.as_slice() => false, + &clean::NameValue(ref x, _) if "doc" == *x => false, _ => true }).map(|x| x.clone()).collect(); if docstr.len() > 0 { @@ -374,14 +374,14 @@ mod unindent_tests { fn should_unindent() { let s = " line1\n line2".to_string(); let r = unindent(s.as_slice()); - assert_eq!(r.as_slice(), "line1\nline2"); + assert_eq!(r, "line1\nline2"); } #[test] fn should_unindent_multiple_paragraphs() { let s = " line1\n\n line2".to_string(); let r = unindent(s.as_slice()); - assert_eq!(r.as_slice(), "line1\n\nline2"); + assert_eq!(r, "line1\n\nline2"); } #[test] @@ -390,7 +390,7 @@ mod unindent_tests { // base indentation and should be preserved let s = " line1\n\n line2".to_string(); let r = unindent(s.as_slice()); - assert_eq!(r.as_slice(), "line1\n\n line2"); + assert_eq!(r, "line1\n\n line2"); } #[test] @@ -402,13 +402,13 @@ mod unindent_tests { // and continue here"] let s = "line1\n line2".to_string(); let r = unindent(s.as_slice()); - assert_eq!(r.as_slice(), "line1\nline2"); + assert_eq!(r, "line1\nline2"); } #[test] fn should_not_ignore_first_line_indent_in_a_single_line_para() { let s = "line1\n\n line2".to_string(); let r = unindent(s.as_slice()); - assert_eq!(r.as_slice(), "line1\n\n line2"); + assert_eq!(r, "line1\n\n line2"); } } From 09f7713dd45c3a0b37073115575697c256238b18 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 14:28:51 -0500 Subject: [PATCH 15/35] libserialize: remove unnecessary `as_slice()` calls --- src/libserialize/base64.rs | 36 ++++++++++++++++-------------------- src/libserialize/hex.rs | 26 +++++++++++--------------- src/libserialize/json.rs | 6 +++--- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index b7d8885a5f993..8efb8e5b78d50 100644 --- a/src/libserialize/base64.rs +++ b/src/libserialize/base64.rs @@ -298,7 +298,6 @@ mod tests { #[test] fn test_to_base64_line_break() { assert!(![0u8, ..1000].to_base64(Config {line_length: None, ..STANDARD}) - .as_slice() .contains("\r\n")); assert_eq!("foobar".as_bytes().to_base64(Config {line_length: Some(4), ..STANDARD}), @@ -319,26 +318,26 @@ mod tests { #[test] fn test_from_base64_basic() { - assert_eq!("".from_base64().unwrap().as_slice(), "".as_bytes()); - assert_eq!("Zg==".from_base64().unwrap().as_slice(), "f".as_bytes()); - assert_eq!("Zm8=".from_base64().unwrap().as_slice(), "fo".as_bytes()); - assert_eq!("Zm9v".from_base64().unwrap().as_slice(), "foo".as_bytes()); - assert_eq!("Zm9vYg==".from_base64().unwrap().as_slice(), "foob".as_bytes()); - assert_eq!("Zm9vYmE=".from_base64().unwrap().as_slice(), "fooba".as_bytes()); - assert_eq!("Zm9vYmFy".from_base64().unwrap().as_slice(), "foobar".as_bytes()); + assert_eq!("".from_base64().unwrap(), b""); + assert_eq!("Zg==".from_base64().unwrap(), b"f"); + assert_eq!("Zm8=".from_base64().unwrap(), b"fo"); + assert_eq!("Zm9v".from_base64().unwrap(), b"foo"); + assert_eq!("Zm9vYg==".from_base64().unwrap(), b"foob"); + assert_eq!("Zm9vYmE=".from_base64().unwrap(), b"fooba"); + assert_eq!("Zm9vYmFy".from_base64().unwrap(), b"foobar"); } #[test] fn test_from_base64_bytes() { - assert_eq!(b"Zm9vYmFy".from_base64().unwrap().as_slice(), "foobar".as_bytes()); + assert_eq!(b"Zm9vYmFy".from_base64().unwrap(), b"foobar"); } #[test] fn test_from_base64_newlines() { - assert_eq!("Zm9v\r\nYmFy".from_base64().unwrap().as_slice(), - "foobar".as_bytes()); - assert_eq!("Zm9vYg==\r\n".from_base64().unwrap().as_slice(), - "foob".as_bytes()); + assert_eq!("Zm9v\r\nYmFy".from_base64().unwrap(), + b"foobar"); + assert_eq!("Zm9vYg==\r\n".from_base64().unwrap(), + b"foob"); } #[test] @@ -364,13 +363,10 @@ mod tests { for _ in range(0u, 1000) { let times = task_rng().gen_range(1u, 100); let v = Vec::from_fn(times, |_| random::()); - assert_eq!(v.as_slice() - .to_base64(STANDARD) - .as_slice() + assert_eq!(v.to_base64(STANDARD) .from_base64() - .unwrap() - .as_slice(), - v.as_slice()); + .unwrap(), + v); } } @@ -390,7 +386,7 @@ mod tests { ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン"; let sb = s.as_bytes().to_base64(STANDARD); b.iter(|| { - sb.as_slice().from_base64().unwrap(); + sb.from_base64().unwrap(); }); b.bytes = sb.len() as u64; } diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index 2a3c410ba7c58..443a31f7493f2 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -163,10 +163,10 @@ mod tests { #[test] pub fn test_from_hex_okay() { - assert_eq!("666f6f626172".from_hex().unwrap().as_slice(), - "foobar".as_bytes()); - assert_eq!("666F6F626172".from_hex().unwrap().as_slice(), - "foobar".as_bytes()); + assert_eq!("666f6f626172".from_hex().unwrap(), + b"foobar"); + assert_eq!("666F6F626172".from_hex().unwrap(), + b"foobar"); } #[test] @@ -182,8 +182,8 @@ mod tests { #[test] pub fn test_from_hex_ignores_whitespace() { - assert_eq!("666f 6f6\r\n26172 ".from_hex().unwrap().as_slice(), - "foobar".as_bytes()); + assert_eq!("666f 6f6\r\n26172 ".from_hex().unwrap(), + b"foobar"); } #[test] @@ -197,15 +197,11 @@ mod tests { pub fn test_from_hex_all_bytes() { for i in range(0u, 256) { let ii: &[u8] = &[i as u8]; - assert_eq!(format!("{:02x}", i as uint).as_slice() - .from_hex() - .unwrap() - .as_slice(), + assert_eq!(format!("{:02x}", i as uint).from_hex() + .unwrap(), ii); - assert_eq!(format!("{:02X}", i as uint).as_slice() - .from_hex() - .unwrap() - .as_slice(), + assert_eq!(format!("{:02X}", i as uint).from_hex() + .unwrap(), ii); } } @@ -226,7 +222,7 @@ mod tests { ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン"; let sb = s.as_bytes().to_hex(); b.iter(|| { - sb.as_slice().from_hex().unwrap(); + sb.from_hex().unwrap(); }); b.bytes = sb.len() as u64; } diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index fa82eb93faeec..abf2341a76cbe 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -2039,7 +2039,7 @@ impl ::Decoder for Decoder { fn read_char(&mut self) -> DecodeResult { let s = try!(self.read_str()); { - let mut it = s.as_slice().chars(); + let mut it = s.chars(); match (it.next(), it.next()) { // exactly one character (Some(c), None) => return Ok(c), @@ -2860,7 +2860,7 @@ mod tests { for &(i, o) in s.iter() { let v: string::String = super::decode(i).unwrap(); - assert_eq!(v.as_slice(), o); + assert_eq!(v, o); } } @@ -3778,7 +3778,7 @@ mod tests { fn bench_streaming_large(b: &mut Bencher) { let src = big_json(); b.iter( || { - let mut parser = Parser::new(src.as_slice().chars()); + let mut parser = Parser::new(src.chars()); loop { match parser.next() { None => return, From 60338d91c4334e5fdfbd37b298cd5b99e8fc0cdd Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 14:43:55 -0500 Subject: [PATCH 16/35] libstd: remove unnecessary `as_slice()` calls --- src/libstd/ascii.rs | 10 +++--- src/libstd/collections/hash/map.rs | 30 ++++++++--------- src/libstd/collections/hash/set.rs | 2 +- src/libstd/io/buffered.rs | 10 +++--- src/libstd/io/comm_adapters.rs | 10 +++--- src/libstd/io/fs.rs | 6 ++-- src/libstd/io/mem.rs | 22 ++++++------ src/libstd/io/mod.rs | 6 ++-- src/libstd/io/process.rs | 21 +++++------- src/libstd/io/stdio.rs | 2 +- src/libstd/os.rs | 6 ++-- src/libstd/path/mod.rs | 2 +- src/libstd/path/posix.rs | 38 ++++++++++----------- src/libstd/path/windows.rs | 54 +++++++++++++++--------------- src/libstd/rand/mod.rs | 6 ++-- src/libstd/sys/windows/fs.rs | 4 +-- src/libstd/sys/windows/process.rs | 4 +-- src/libstd/sys/windows/tty.rs | 2 +- src/libstd/task.rs | 4 +-- 19 files changed, 118 insertions(+), 121 deletions(-) diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 403ca9d14321a..f31c694098f40 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -677,8 +677,8 @@ mod tests { assert_eq!(test.to_ascii(), b); assert_eq!("( ;".to_ascii(), b); let v = vec![40u8, 32u8, 59u8]; - assert_eq!(v.as_slice().to_ascii(), b); - assert_eq!("( ;".to_string().as_slice().to_ascii(), b); + assert_eq!(v.to_ascii(), b); + assert_eq!("( ;".to_string().to_ascii(), b); assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#".to_string()); assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#".to_string()); @@ -780,7 +780,7 @@ mod tests { while i <= 500 { let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 } else { i }; - assert_eq!((from_u32(i).unwrap()).to_string().as_slice().to_ascii_upper(), + assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_upper(), (from_u32(upper).unwrap()).to_string()) i += 1; } @@ -796,7 +796,7 @@ mod tests { while i <= 500 { let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 } else { i }; - assert_eq!((from_u32(i).unwrap()).to_string().as_slice().to_ascii_lower(), + assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_lower(), (from_u32(lower).unwrap()).to_string()) i += 1; } @@ -850,7 +850,7 @@ mod tests { let c = i; let lower = if 'A' as u32 <= c && c <= 'Z' as u32 { c + 'a' as u32 - 'A' as u32 } else { c }; - assert!((from_u32(i).unwrap()).to_string().as_slice().eq_ignore_ascii_case( + assert!((from_u32(i).unwrap()).to_string().eq_ignore_ascii_case( (from_u32(lower).unwrap()).to_string().as_slice())); i += 1; } diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index cf09c93f91785..1fb6279d004b5 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1546,7 +1546,7 @@ mod test_map { DROP_VECTOR.with(|v| { for i in range(0u, 200) { - assert_eq!(v.borrow().as_slice()[i], 0); + assert_eq!(v.borrow()[i], 0); } }); @@ -1558,7 +1558,7 @@ mod test_map { DROP_VECTOR.with(|v| { for i in range(0u, 200) { - assert_eq!(v.borrow().as_slice()[i], 1); + assert_eq!(v.borrow()[i], 1); } }); @@ -1569,27 +1569,27 @@ mod test_map { assert!(v.is_some()); DROP_VECTOR.with(|v| { - assert_eq!(v.borrow().as_slice()[i], 1); - assert_eq!(v.borrow().as_slice()[i+100], 1); + assert_eq!(v.borrow()[i], 1); + assert_eq!(v.borrow()[i+100], 1); }); } DROP_VECTOR.with(|v| { for i in range(0u, 50) { - assert_eq!(v.borrow().as_slice()[i], 0); - assert_eq!(v.borrow().as_slice()[i+100], 0); + assert_eq!(v.borrow()[i], 0); + assert_eq!(v.borrow()[i+100], 0); } for i in range(50u, 100) { - assert_eq!(v.borrow().as_slice()[i], 1); - assert_eq!(v.borrow().as_slice()[i+100], 1); + assert_eq!(v.borrow()[i], 1); + assert_eq!(v.borrow()[i+100], 1); } }); } DROP_VECTOR.with(|v| { for i in range(0u, 200) { - assert_eq!(v.borrow().as_slice()[i], 0); + assert_eq!(v.borrow()[i], 0); } }); } @@ -1605,7 +1605,7 @@ mod test_map { DROP_VECTOR.with(|v| { for i in range(0u, 200) { - assert_eq!(v.borrow().as_slice()[i], 0); + assert_eq!(v.borrow()[i], 0); } }); @@ -1617,7 +1617,7 @@ mod test_map { DROP_VECTOR.with(|v| { for i in range(0u, 200) { - assert_eq!(v.borrow().as_slice()[i], 1); + assert_eq!(v.borrow()[i], 1); } }); @@ -1632,7 +1632,7 @@ mod test_map { DROP_VECTOR.with(|v| { for i in range(0u, 200) { - assert_eq!(v.borrow().as_slice()[i], 1); + assert_eq!(v.borrow()[i], 1); } }); @@ -1640,11 +1640,11 @@ mod test_map { DROP_VECTOR.with(|v| { let nk = range(0u, 100).filter(|&i| { - v.borrow().as_slice()[i] == 1 + v.borrow()[i] == 1 }).count(); let nv = range(0u, 100).filter(|&i| { - v.borrow().as_slice()[i+100] == 1 + v.borrow()[i+100] == 1 }).count(); assert_eq!(nk, 50); @@ -1654,7 +1654,7 @@ mod test_map { DROP_VECTOR.with(|v| { for i in range(0u, 200) { - assert_eq!(v.borrow().as_slice()[i], 0); + assert_eq!(v.borrow()[i], 0); } }); } diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index b40622171d52a..9c9f23369e562 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -827,7 +827,7 @@ mod test_set { }; let v = hs.into_iter().collect::>(); - assert!(['a', 'b'][] == v.as_slice() || ['b', 'a'][] == v.as_slice()); + assert!(['a', 'b'] == v || ['b', 'a'] == v); } #[test] diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index fba9e4f2e25e1..6ed0498b0ccd1 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -449,30 +449,30 @@ mod test { let nread = reader.read(&mut buf); assert_eq!(Ok(3), nread); let b: &[_] = &[5, 6, 7]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); let mut buf = [0, 0]; let nread = reader.read(&mut buf); assert_eq!(Ok(2), nread); let b: &[_] = &[0, 1]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); let mut buf = [0]; let nread = reader.read(&mut buf); assert_eq!(Ok(1), nread); let b: &[_] = &[2]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); let mut buf = [0, 0, 0]; let nread = reader.read(&mut buf); assert_eq!(Ok(1), nread); let b: &[_] = &[3, 0, 0]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); let nread = reader.read(&mut buf); assert_eq!(Ok(1), nread); let b: &[_] = &[4, 0, 0]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); assert!(reader.read(&mut buf).is_err()); } diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index a90b6bbbb8e8e..c91769ed5035e 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -176,28 +176,28 @@ mod test { assert_eq!(Ok(3), reader.read(&mut buf)); let a: &[u8] = &[1,2,3]; - assert_eq!(a, buf.as_slice()); + assert_eq!(a, buf); assert_eq!(Ok(3), reader.read(&mut buf)); let a: &[u8] = &[4,5,6]; - assert_eq!(a, buf.as_slice()); + assert_eq!(a, buf); assert_eq!(Ok(2), reader.read(&mut buf)); let a: &[u8] = &[7,8,6]; - assert_eq!(a, buf.as_slice()); + assert_eq!(a, buf); match reader.read(buf.as_mut_slice()) { Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, io::EndOfFile), } - assert_eq!(a, buf.as_slice()); + assert_eq!(a, buf); // Ensure it continues to panic in the same way. match reader.read(buf.as_mut_slice()) { Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, io::EndOfFile), } - assert_eq!(a, buf.as_slice()); + assert_eq!(a, buf); } #[test] diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index e52c00f8247a8..4c7f768f7d345 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -837,7 +837,7 @@ mod test { macro_rules! error( ($e:expr, $s:expr) => ( match $e { Ok(_) => panic!("Unexpected success. Should've been: {}", $s), - Err(ref err) => assert!(err.to_string().as_slice().contains($s.as_slice()), + Err(ref err) => assert!(err.to_string().contains($s.as_slice()), format!("`{}` did not contain `{}`", err, $s)) } ) ) @@ -995,7 +995,7 @@ mod test { } check!(unlink(filename)); let read_str = str::from_utf8(&read_mem).unwrap(); - assert!(read_str.as_slice() == final_msg.as_slice()); + assert!(read_str == final_msg); } #[test] @@ -1103,7 +1103,7 @@ mod test { let f = dir.join(format!("{}.txt", n)); let mut w = check!(File::create(&f)); let msg_str = format!("{}{}", prefix, n.to_string()); - let msg = msg_str.as_slice().as_bytes(); + let msg = msg_str.as_bytes(); check!(w.write(msg)); } let files = check!(readdir(dir)); diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index c5cd95f8501fa..c48f487c95cf7 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -444,7 +444,7 @@ mod test { assert_eq!(writer.write(&[10]).unwrap_err().kind, io::EndOfFile); } let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); } #[test] @@ -473,7 +473,7 @@ mod test { } let b: &[_] = &[1, 3, 2, 0, 0, 0, 0, 4]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); } #[test] @@ -498,12 +498,12 @@ mod test { assert_eq!(reader.read(&mut buf), Ok(1)); assert_eq!(reader.tell(), Ok(1)); let b: &[_] = &[0]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); let mut buf = [0, ..4]; assert_eq!(reader.read(&mut buf), Ok(4)); assert_eq!(reader.tell(), Ok(5)); let b: &[_] = &[1, 2, 3, 4]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); assert_eq!(reader.read(&mut buf), Ok(3)); let b: &[_] = &[5, 6, 7]; assert_eq!(buf[0..3], b); @@ -551,12 +551,12 @@ mod test { assert_eq!(reader.read(&mut buf), Ok(1)); assert_eq!(reader.tell(), Ok(1)); let b: &[_] = &[0]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); let mut buf = [0, ..4]; assert_eq!(reader.read(&mut buf), Ok(4)); assert_eq!(reader.tell(), Ok(5)); let b: &[_] = &[1, 2, 3, 4]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); assert_eq!(reader.read(&mut buf), Ok(3)); let b: &[_] = &[5, 6, 7]; assert_eq!(buf[0..3], b); @@ -652,15 +652,15 @@ mod test { let mut buf = [0, ..3]; assert!(r.read_at_least(buf.len(), &mut buf).is_ok()); let b: &[_] = &[1, 2, 3]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); assert!(r.read_at_least(0, buf[mut ..0]).is_ok()); - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); assert!(r.read_at_least(buf.len(), &mut buf).is_ok()); let b: &[_] = &[4, 5, 6]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); assert!(r.read_at_least(buf.len(), &mut buf).is_err()); let b: &[_] = &[7, 8, 6]; - assert_eq!(buf.as_slice(), b); + assert_eq!(buf, b); } fn do_bench_mem_writer(b: &mut Bencher, times: uint, len: uint) { @@ -757,7 +757,7 @@ mod test { for _i in range(0u, 10) { let mut buf = [0 as u8, .. 10]; rdr.read(&mut buf).unwrap(); - assert_eq!(buf.as_slice(), [5, .. 10].as_slice()); + assert_eq!(buf, [5, .. 10]); } } }); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index b2e4fc75cf238..5a56636ffa41c 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -238,8 +238,8 @@ use os; use boxed::Box; use result::{Ok, Err, Result}; use sys; -use slice::{AsSlice, SlicePrelude}; -use str::{Str, StrPrelude}; +use slice::SlicePrelude; +use str::StrPrelude; use str; use string::String; use uint; @@ -316,7 +316,7 @@ impl IoError { pub fn from_errno(errno: uint, detail: bool) -> IoError { let mut err = sys::decode_error(errno as i32); if detail && err.kind == OtherIoError { - err.detail = Some(os::error_string(errno).as_slice().chars() + err.detail = Some(os::error_string(errno).chars() .map(|c| c.to_lowercase()).collect()) } err diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index d4d24c1e12fc8..53c672b4302d4 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -236,8 +236,8 @@ impl Command { // if the env is currently just inheriting from the parent's, // materialize the parent's env into a hashtable. self.env = Some(os::env_as_bytes().into_iter() - .map(|(k, v)| (EnvKey(k.as_slice().to_c_str()), - v.as_slice().to_c_str())) + .map(|(k, v)| (EnvKey(k.to_c_str()), + v.to_c_str())) .collect()); self.env.as_mut().unwrap() } @@ -973,7 +973,7 @@ mod tests { let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap(); let parent_dir = os::getcwd().unwrap(); - let child_dir = Path::new(output.as_slice().trim()); + let child_dir = Path::new(output.trim()); let parent_stat = parent_dir.stat().unwrap(); let child_stat = child_dir.stat().unwrap(); @@ -991,7 +991,7 @@ mod tests { let prog = pwd_cmd().cwd(&parent_dir).spawn().unwrap(); let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap(); - let child_dir = Path::new(output.as_slice().trim()); + let child_dir = Path::new(output.trim()); let parent_stat = parent_dir.stat().unwrap(); let child_stat = child_dir.stat().unwrap(); @@ -1031,8 +1031,7 @@ mod tests { for &(ref k, ref v) in r.iter() { // don't check windows magical empty-named variables assert!(k.is_empty() || - output.as_slice() - .contains(format!("{}={}", *k, *v).as_slice()), + output.contains(format!("{}={}", *k, *v).as_slice()), "output doesn't contain `{}={}`\n{}", k, v, output); } @@ -1050,12 +1049,10 @@ mod tests { for &(ref k, ref v) in r.iter() { // don't check android RANDOM variables if *k != "RANDOM".to_string() { - assert!(output.as_slice() - .contains(format!("{}={}", + assert!(output..contains(format!("{}={}", *k, *v).as_slice()) || - output.as_slice() - .contains(format!("{}=\'{}\'", + output..contains(format!("{}=\'{}\'", *k, *v).as_slice())); } @@ -1084,7 +1081,7 @@ mod tests { let result = prog.wait_with_output().unwrap(); let output = String::from_utf8_lossy(result.output.as_slice()).into_string(); - assert!(output.as_slice().contains("RUN_TEST_NEW_ENV=123"), + assert!(output.contains("RUN_TEST_NEW_ENV=123"), "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output); } @@ -1094,7 +1091,7 @@ mod tests { let result = prog.wait_with_output().unwrap(); let output = String::from_utf8_lossy(result.output.as_slice()).into_string(); - assert!(output.as_slice().contains("RUN_TEST_NEW_ENV=123"), + assert!(output.contains("RUN_TEST_NEW_ENV=123"), "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output); } diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index ad5dcf71df737..89d5b7a8acd92 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -542,6 +542,6 @@ mod tests { panic!("my special message"); }); let s = r.read_to_string().unwrap(); - assert!(s.as_slice().contains("my special message")); + assert!(s.contains("my special message")); } } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index a8adfec34ed68..3faf7c89e63b2 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -313,7 +313,7 @@ pub fn env_as_bytes() -> Vec<(Vec,Vec)> { fn env_convert(input: Vec>) -> Vec<(Vec, Vec)> { let mut pairs = Vec::new(); for p in input.iter() { - let mut it = p.as_slice().splitn(1, |b| *b == b'='); + let mut it = p.splitn(1, |b| *b == b'='); let key = it.next().unwrap().to_vec(); let default: &[u8] = &[]; let val = it.next().unwrap_or(default).to_vec(); @@ -2066,7 +2066,7 @@ mod tests { #[cfg(unix)] fn join_paths_unix() { fn test_eq(input: &[&str], output: &str) -> bool { - join_paths(input).unwrap().as_slice() == output.as_bytes() + join_paths(input).unwrap() == output.as_bytes() } assert!(test_eq(&[], "")); @@ -2081,7 +2081,7 @@ mod tests { #[cfg(windows)] fn join_paths_windows() { fn test_eq(input: &[&str], output: &str) -> bool { - join_paths(input).unwrap().as_slice() == output.as_bytes() + join_paths(input).unwrap() == output.as_bytes() } assert!(test_eq(&[], "")); diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index b17106e811f62..86d55727a5a62 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -941,6 +941,6 @@ mod tests { let input = r"\foo\bar\baz"; let path: WindowsPath = WindowsPath::new(input.to_c_str()); - assert_eq!(path.as_str().unwrap(), input.as_slice()); + assert_eq!(path.as_str().unwrap(), input); } } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index f6778588addb9..e76d2ed169ded 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -131,7 +131,7 @@ impl GenericPathUnsafe for Path { unsafe fn set_filename_unchecked(&mut self, filename: T) { let filename = filename.container_as_bytes(); match self.sepidx { - None if b".." == self.repr.as_slice() => { + None if b".." == self.repr => { let mut v = Vec::with_capacity(3 + filename.len()); v.push_all(dot_dot_static); v.push(SEP_BYTE); @@ -158,7 +158,7 @@ impl GenericPathUnsafe for Path { self.repr = Path::normalize(v.as_slice()); } } - self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE); + self.sepidx = self.repr.rposition_elem(&SEP_BYTE); } unsafe fn push_unchecked(&mut self, path: T) { @@ -174,7 +174,7 @@ impl GenericPathUnsafe for Path { // FIXME: this is slow self.repr = Path::normalize(v.as_slice()); } - self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE); + self.sepidx = self.repr.rposition_elem(&SEP_BYTE); } } } @@ -191,7 +191,7 @@ impl GenericPath for Path { fn dirname<'a>(&'a self) -> &'a [u8] { match self.sepidx { - None if b".." == self.repr.as_slice() => self.repr.as_slice(), + None if b".." == self.repr => self.repr.as_slice(), None => dot_static, Some(0) => self.repr[..1], Some(idx) if self.repr[idx+1..] == b".." => self.repr.as_slice(), @@ -201,8 +201,8 @@ impl GenericPath for Path { fn filename<'a>(&'a self) -> Option<&'a [u8]> { match self.sepidx { - None if b"." == self.repr.as_slice() || - b".." == self.repr.as_slice() => None, + None if b"." == self.repr || + b".." == self.repr => None, None => Some(self.repr.as_slice()), Some(idx) if self.repr[idx+1..] == b".." => None, Some(0) if self.repr[1..].is_empty() => None, @@ -212,20 +212,20 @@ impl GenericPath for Path { fn pop(&mut self) -> bool { match self.sepidx { - None if b"." == self.repr.as_slice() => false, + None if b"." == self.repr => false, None => { self.repr = vec![b'.']; self.sepidx = None; true } - Some(0) if b"/" == self.repr.as_slice() => false, + Some(0) if b"/" == self.repr => false, Some(idx) => { if idx == 0 { self.repr.truncate(idx+1); } else { self.repr.truncate(idx); } - self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE); + self.sepidx = self.repr.rposition_elem(&SEP_BYTE); true } } @@ -250,7 +250,7 @@ impl GenericPath for Path { } else { let mut ita = self.components(); let mut itb = other.components(); - if b"." == self.repr.as_slice() { + if b"." == self.repr { return match itb.next() { None => true, Some(b) => b != b".." @@ -305,7 +305,7 @@ impl GenericPath for Path { } } } - Some(Path::new(comps.as_slice().connect_vec(&SEP_BYTE))) + Some(Path::new(comps.connect_vec(&SEP_BYTE))) } } @@ -406,7 +406,7 @@ impl Path { // None result means the byte vector didn't need normalizing fn normalize_helper<'a>(v: &'a [u8], is_abs: bool) -> Option> { - if is_abs && v.as_slice().is_empty() { + if is_abs && v.is_empty() { return None; } let mut comps: Vec<&'a [u8]> = vec![]; @@ -495,8 +495,8 @@ mod tests { t!(s: Path::new("foo/../../.."), "../.."); t!(s: Path::new("foo/../../bar"), "../bar"); - assert_eq!(Path::new(b"foo/bar").into_vec().as_slice(), b"foo/bar"); - assert_eq!(Path::new(b"/foo/../../bar").into_vec().as_slice(), + assert_eq!(Path::new(b"foo/bar").into_vec(), b"foo/bar"); + assert_eq!(Path::new(b"/foo/../../bar").into_vec(), b"/bar"); let p = Path::new(b"foo/bar\x80"); @@ -536,7 +536,7 @@ mod tests { ($path:expr, $disp:ident, $exp:expr) => ( { let path = Path::new($path); - assert!(path.$disp().to_string().as_slice() == $exp); + assert!(path.$disp().to_string() == $exp); } ) ) @@ -579,9 +579,9 @@ mod tests { { let path = Path::new($path); let f = format!("{}", path.display()); - assert!(f.as_slice() == $exp); + assert!(f == $exp); let f = format!("{}", path.filename_display()); - assert!(f.as_slice() == $expf); + assert!(f == $expf); } ) ) @@ -1179,7 +1179,7 @@ mod tests { let path = Path::new($arg); let comps = path.components().collect::>(); let exp: &[&[u8]] = &[$($exp),*]; - assert_eq!(comps.as_slice(), exp); + assert_eq!(comps, exp); let comps = path.components().rev().collect::>(); let exp = exp.iter().rev().map(|&x|x).collect::>(); assert_eq!(comps, exp) @@ -1211,7 +1211,7 @@ mod tests { let path = Path::new($arg); let comps = path.str_components().collect::>>(); let exp: &[Option<&str>] = &$exp; - assert_eq!(comps.as_slice(), exp); + assert_eq!(comps, exp); let comps = path.str_components().rev().collect::>>(); let exp = exp.iter().rev().map(|&x|x).collect::>>(); assert_eq!(comps, exp); diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 13891a6333014..366e3125c6587 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -181,7 +181,7 @@ impl GenericPathUnsafe for Path { unsafe fn set_filename_unchecked(&mut self, filename: T) { let filename = filename.container_as_str().unwrap(); match self.sepidx_or_prefix_len() { - None if ".." == self.repr.as_slice() => { + None if ".." == self.repr => { let mut s = String::with_capacity(3 + filename.len()); s.push_str(".."); s.push(SEP); @@ -191,22 +191,22 @@ impl GenericPathUnsafe for Path { None => { self.update_normalized(filename); } - Some((_,idxa,end)) if self.repr.as_slice().slice(idxa,end) == ".." => { + Some((_,idxa,end)) if self.repr.slice(idxa,end) == ".." => { let mut s = String::with_capacity(end + 1 + filename.len()); - s.push_str(self.repr.as_slice().slice_to(end)); + s.push_str(self.repr.slice_to(end)); s.push(SEP); s.push_str(filename); self.update_normalized(s); } Some((idxb,idxa,_)) if self.prefix == Some(DiskPrefix) && idxa == self.prefix_len() => { let mut s = String::with_capacity(idxb + filename.len()); - s.push_str(self.repr.as_slice().slice_to(idxb)); + s.push_str(self.repr.slice_to(idxb)); s.push_str(filename); self.update_normalized(s); } Some((idxb,_,_)) => { let mut s = String::with_capacity(idxb + 1 + filename.len()); - s.push_str(self.repr.as_slice().slice_to(idxb)); + s.push_str(self.repr.slice_to(idxb)); s.push(SEP); s.push_str(filename); self.update_normalized(s); @@ -355,21 +355,21 @@ impl GenericPath for Path { /// Always returns a `Some` value. fn dirname_str<'a>(&'a self) -> Option<&'a str> { Some(match self.sepidx_or_prefix_len() { - None if ".." == self.repr.as_slice() => self.repr.as_slice(), + None if ".." == self.repr => self.repr.as_slice(), None => ".", - Some((_,idxa,end)) if self.repr.as_slice().slice(idxa, end) == ".." => { + Some((_,idxa,end)) if self.repr.slice(idxa, end) == ".." => { self.repr.as_slice() } - Some((idxb,_,end)) if self.repr.as_slice().slice(idxb, end) == "\\" => { + Some((idxb,_,end)) if self.repr.slice(idxb, end) == "\\" => { self.repr.as_slice() } - Some((0,idxa,_)) => self.repr.as_slice().slice_to(idxa), + Some((0,idxa,_)) => self.repr.slice_to(idxa), Some((idxb,idxa,_)) => { match self.prefix { Some(DiskPrefix) | Some(VerbatimDiskPrefix) if idxb == self.prefix_len() => { - self.repr.as_slice().slice_to(idxa) + self.repr.slice_to(idxa) } - _ => self.repr.as_slice().slice_to(idxb) + _ => self.repr.slice_to(idxb) } } }) @@ -414,14 +414,14 @@ impl GenericPath for Path { #[inline] fn pop(&mut self) -> bool { match self.sepidx_or_prefix_len() { - None if "." == self.repr.as_slice() => false, + None if "." == self.repr => false, None => { self.repr = String::from_str("."); self.sepidx = None; true } Some((idxb,idxa,end)) if idxb == idxa && idxb == end => false, - Some((idxb,_,end)) if self.repr.as_slice().slice(idxb, end) == "\\" => false, + Some((idxb,_,end)) if self.repr.slice(idxb, end) == "\\" => false, Some((idxb,idxa,_)) => { let trunc = match self.prefix { Some(DiskPrefix) | Some(VerbatimDiskPrefix) | None => { @@ -441,15 +441,15 @@ impl GenericPath for Path { if self.prefix.is_some() { Some(Path::new(match self.prefix { Some(DiskPrefix) if self.is_absolute() => { - self.repr.as_slice().slice_to(self.prefix_len()+1) + self.repr.slice_to(self.prefix_len()+1) } Some(VerbatimDiskPrefix) => { - self.repr.as_slice().slice_to(self.prefix_len()+1) + self.repr.slice_to(self.prefix_len()+1) } - _ => self.repr.as_slice().slice_to(self.prefix_len()) + _ => self.repr.slice_to(self.prefix_len()) })) } else if is_vol_relative(self) { - Some(Path::new(self.repr.as_slice().slice_to(1))) + Some(Path::new(self.repr.slice_to(1))) } else { None } @@ -468,7 +468,7 @@ impl GenericPath for Path { fn is_absolute(&self) -> bool { match self.prefix { Some(DiskPrefix) => { - let rest = self.repr.as_slice().slice_from(self.prefix_len()); + let rest = self.repr.slice_from(self.prefix_len()); rest.len() > 0 && rest.as_bytes()[0] == SEP_BYTE } Some(_) => true, @@ -490,7 +490,7 @@ impl GenericPath for Path { } else { let mut ita = self.str_components().map(|x|x.unwrap()); let mut itb = other.str_components().map(|x|x.unwrap()); - if "." == self.repr.as_slice() { + if "." == self.repr { return itb.next() != Some(".."); } loop { @@ -826,7 +826,7 @@ impl Path { fn update_sepidx(&mut self) { let s = if self.has_nonsemantic_trailing_slash() { - self.repr.as_slice().slice_to(self.repr.len()-1) + self.repr.slice_to(self.repr.len()-1) } else { self.repr.as_slice() }; let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep } else { is_sep_verbatim }); @@ -922,7 +922,7 @@ pub fn make_non_verbatim(path: &Path) -> Option { } // now ensure normalization didn't change anything if repr.slice_from(path.prefix_len()) == - new_path.repr.as_slice().slice_from(new_path.prefix_len()) { + new_path.repr.slice_from(new_path.prefix_len()) { Some(new_path) } else { None @@ -1232,8 +1232,8 @@ mod tests { t!(s: Path::new("foo\\..\\..\\.."), "..\\.."); t!(s: Path::new("foo\\..\\..\\bar"), "..\\bar"); - assert_eq!(Path::new(b"foo\\bar").into_vec().as_slice(), b"foo\\bar"); - assert_eq!(Path::new(b"\\foo\\..\\..\\bar").into_vec().as_slice(), b"\\bar"); + assert_eq!(Path::new(b"foo\\bar").into_vec(), b"foo\\bar"); + assert_eq!(Path::new(b"\\foo\\..\\..\\bar").into_vec(), b"\\bar"); t!(s: Path::new("\\\\a"), "\\a"); t!(s: Path::new("\\\\a\\"), "\\a"); @@ -1340,9 +1340,9 @@ mod tests { { let path = Path::new($path); let f = format!("{}", path.display()); - assert_eq!(f.as_slice(), $exp); + assert_eq!(f, $exp); let f = format!("{}", path.filename_display()); - assert_eq!(f.as_slice(), $expf); + assert_eq!(f, $expf); } ) ) @@ -2245,7 +2245,7 @@ mod tests { let comps = path.str_components().map(|x|x.unwrap()) .collect::>(); let exp: &[&str] = &$exp; - assert_eq!(comps.as_slice(), exp); + assert_eq!(comps, exp); let comps = path.str_components().rev().map(|x|x.unwrap()) .collect::>(); let exp = exp.iter().rev().map(|&x|x).collect::>(); @@ -2302,7 +2302,7 @@ mod tests { let path = Path::new($path); let comps = path.components().collect::>(); let exp: &[&[u8]] = &$exp; - assert_eq!(comps.as_slice(), exp); + assert_eq!(comps, exp); let comps = path.components().rev().collect::>(); let exp = exp.iter().rev().map(|&x|x).collect::>(); assert_eq!(comps, exp); diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index da690f5d154df..c8030b026d19c 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -529,7 +529,7 @@ mod test { let mut one = [1i]; r.shuffle(&mut one); let b: &[_] = &[1]; - assert_eq!(one.as_slice(), b); + assert_eq!(one, b); let mut two = [1i, 2]; r.shuffle(&mut two); @@ -538,7 +538,7 @@ mod test { let mut x = [1i, 1, 1]; r.shuffle(&mut x); let b: &[_] = &[1, 1, 1]; - assert_eq!(x.as_slice(), b); + assert_eq!(x, b); } #[test] @@ -548,7 +548,7 @@ mod test { let mut v = [1i, 1, 1]; r.shuffle(&mut v); let b: &[_] = &[1, 1, 1]; - assert_eq!(v.as_slice(), b); + assert_eq!(v, b); assert_eq!(r.gen_range(0u, 1u), 0u); } diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 9402c63dcf558..16779a80185bc 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -376,8 +376,8 @@ pub fn readlink(p: &Path) -> IoResult { libc::VOLUME_NAME_DOS) }); let ret = match ret { - Some(ref s) if s.as_slice().starts_with(r"\\?\") => { // " - Ok(Path::new(s.as_slice().slice_from(4))) + Some(ref s) if s.starts_with(r"\\?\") => { // " + Ok(Path::new(s.slice_from(4))) } Some(s) => Ok(Path::new(s)), None => Err(super::last_error()), diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 78a8e09dac1a0..2af5e4890e849 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -223,7 +223,7 @@ impl Process { with_envp(cfg.env(), |envp| { with_dirp(cfg.cwd(), |dirp| { - let mut cmd_str: Vec = cmd_str.as_slice().utf16_units().collect(); + let mut cmd_str: Vec = cmd_str.utf16_units().collect(); cmd_str.push(0); let created = CreateProcessW(ptr::null(), cmd_str.as_mut_ptr(), @@ -433,7 +433,7 @@ fn with_envp(env: Option<&collections::HashMap>, let kv = format!("{}={}", pair.ref0().container_as_str().unwrap(), pair.ref1().container_as_str().unwrap()); - blk.extend(kv.as_slice().utf16_units()); + blk.extend(kv.utf16_units()); blk.push(0); } diff --git a/src/libstd/sys/windows/tty.rs b/src/libstd/sys/windows/tty.rs index 0e7b06cbb9478..51679bb2003fc 100644 --- a/src/libstd/sys/windows/tty.rs +++ b/src/libstd/sys/windows/tty.rs @@ -113,7 +113,7 @@ impl TTY { pub fn write(&mut self, buf: &[u8]) -> IoResult<()> { let utf16 = match from_utf8(buf) { Some(utf8) => { - utf8.as_slice().utf16_units().collect::>() + utf8.utf16_units().collect::>() } None => return Err(invalid_encoding()), }; diff --git a/src/libstd/task.rs b/src/libstd/task.rs index a0ee08570d90d..c433dfa08f4f6 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -54,7 +54,7 @@ use result::Result; use rustrt::local::Local; use rustrt::task::Task; use rustrt::task; -use str::{Str, SendStr}; +use str::SendStr; use string::{String, ToString}; use sync::Future; @@ -242,7 +242,7 @@ pub fn name() -> Option { let task = Local::borrow(None::); match task.name { - Some(ref name) => Some(name.as_slice().to_string()), + Some(ref name) => Some(name.to_string()), None => None } } From 39f44c0c20977bc0ff5562d8bca27b11248abbd4 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 15:00:50 -0500 Subject: [PATCH 17/35] libsyntax: remove unnecessary `as_slice()` calls --- src/libsyntax/ast_map/mod.rs | 2 +- src/libsyntax/codemap.rs | 18 +++++++++--------- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/feature_gate.rs | 2 +- src/libsyntax/parse/lexer/comments.rs | 15 +++++++-------- src/libsyntax/parse/lexer/mod.rs | 5 ++--- src/libsyntax/print/pprust.rs | 2 +- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index 2913666a31535..ce2fe6e722096 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -260,7 +260,7 @@ impl<'ast> Map<'ast> { } fn find_entry(&self, id: NodeId) -> Option> { - self.map.borrow().as_slice().get(id as uint).map(|e| *e) + self.map.borrow().get(id as uint).map(|e| *e) } pub fn krate(&self) -> &'ast Crate { diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 27e8c265e5c34..7df09260cfc2f 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -290,7 +290,7 @@ impl FileMap { lines.get(line_number).map(|&line| { let begin: BytePos = line - self.start_pos; let begin = begin.to_uint(); - let slice = self.src.as_slice().slice_from(begin); + let slice = self.src.slice_from(begin); match slice.find('\n') { Some(e) => slice.slice_to(e), None => slice @@ -308,8 +308,8 @@ impl FileMap { } pub fn is_real_file(&self) -> bool { - !(self.name.as_slice().starts_with("<") && - self.name.as_slice().ends_with(">")) + !(self.name.starts_with("<") && + self.name.ends_with(">")) } } @@ -336,8 +336,8 @@ impl CodeMap { // Remove utf-8 BOM if any. // FIXME #12884: no efficient/safe way to remove from the start of a string // and reuse the allocation. - let mut src = if src.as_slice().starts_with("\ufeff") { - String::from_str(src.as_slice().slice_from(3)) + let mut src = if src.starts_with("\ufeff") { + String::from_str(src.slice_from(3)) } else { String::from_str(src.as_slice()) }; @@ -346,7 +346,7 @@ impl CodeMap { // This is a workaround to prevent CodeMap.lookup_filemap_idx from accidentally // overflowing into the next filemap in case the last byte of span is also the last // byte of filemap, which leads to incorrect results from CodeMap.span_to_*. - if src.len() > 0 && !src.as_slice().ends_with("\n") { + if src.len() > 0 && !src.ends_with("\n") { src.push('\n'); } @@ -426,14 +426,14 @@ impl CodeMap { if begin.fm.start_pos != end.fm.start_pos { None } else { - Some(begin.fm.src.as_slice().slice(begin.pos.to_uint(), - end.pos.to_uint()).to_string()) + Some(begin.fm.src.slice(begin.pos.to_uint(), + end.pos.to_uint()).to_string()) } } pub fn get_filemap(&self, filename: &str) -> Rc { for fm in self.files.borrow().iter() { - if filename == fm.name.as_slice() { + if filename == fm.name { return fm.clone(); } } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 8d0d399fa3153..0787518f04fb6 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -527,7 +527,7 @@ impl<'a> ExtCtxt<'a> { let mut call_site = None; loop { let expn_info = self.codemap().with_expn_info(expn_id, |ei| { - ei.map(|ei| (ei.call_site, ei.callee.name.as_slice() == "include")) + ei.map(|ei| (ei.call_site, ei.callee.name == "include")) }); match expn_info { None => break, diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 11c65d531f6fd..4af7b35079a63 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -132,7 +132,7 @@ impl<'a> Context<'a> { } fn has_feature(&self, feature: &str) -> bool { - self.features.iter().any(|n| n.as_slice() == feature) + self.features.iter().any(|&n| n == feature) } } diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index b62d2d744c9e0..f9877d937ca16 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -66,21 +66,20 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { let mut j = lines.len(); // first line of all-stars should be omitted if lines.len() > 0 && - lines[0].as_slice().chars().all(|c| c == '*') { + lines[0].chars().all(|c| c == '*') { i += 1; } - while i < j && lines[i].as_slice().trim().is_empty() { + while i < j && lines[i].trim().is_empty() { i += 1; } // like the first, a last line of all stars should be omitted if j > i && lines[j - 1] - .as_slice() .chars() .skip(1) .all(|c| c == '*') { j -= 1; } - while j > i && lines[j - 1].as_slice().trim().is_empty() { + while j > i && lines[j - 1].trim().is_empty() { j -= 1; } return lines.slice(i, j).iter().map(|x| (*x).clone()).collect(); @@ -92,7 +91,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { let mut can_trim = true; let mut first = true; for line in lines.iter() { - for (j, c) in line.as_slice().chars().enumerate() { + for (j, c) in line.chars().enumerate() { if j > i || !"* \t".contains_char(c) { can_trim = false; break; @@ -117,7 +116,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { if can_trim { lines.iter().map(|line| { - line.as_slice().slice(i + 1, line.len()).to_string() + line.slice(i + 1, line.len()).to_string() }).collect() } else { lines @@ -228,7 +227,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut Vec , let s1 = match all_whitespace(s.as_slice(), col) { Some(col) => { if col < len { - s.as_slice().slice(col, len).to_string() + s.slice(col, len).to_string() } else { "".to_string() } @@ -265,7 +264,7 @@ fn read_block_comment(rdr: &mut StringReader, if is_block_doc_comment(curr_line.as_slice()) { return } - assert!(!curr_line.as_slice().contains_char('\n')); + assert!(!curr_line.contains_char('\n')); lines.push(curr_line); } else { let mut level: int = 1; diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 27b65e0f52798..2a77e3e67915b 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -265,7 +265,7 @@ impl<'a> StringReader<'a> { /// Calls `f` with a string slice of the source text spanning from `start` /// up to but excluding `end`. fn with_str_from_to(&self, start: BytePos, end: BytePos, f: |s: &str| -> T) -> T { - f(self.filemap.src.as_slice().slice( + f(self.filemap.src.slice( self.byte_offset(start).to_uint(), self.byte_offset(end).to_uint())) } @@ -321,7 +321,6 @@ impl<'a> StringReader<'a> { let last_char = self.curr.unwrap(); let next = self.filemap .src - .as_slice() .char_range_at(current_byte_offset); let byte_offset_diff = next.next - current_byte_offset; self.pos = self.pos + Pos::from_uint(byte_offset_diff); @@ -343,7 +342,7 @@ impl<'a> StringReader<'a> { pub fn nextch(&self) -> Option { let offset = self.byte_offset(self.pos).to_uint(); if offset < self.filemap.src.len() { - Some(self.filemap.src.as_slice().char_at(offset)) + Some(self.filemap.src.char_at(offset)) } else { None } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index e9937dc9b6045..40303cdffe3f1 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2844,7 +2844,7 @@ impl<'a> State<'a> { comments::BlankLine => { // We need to do at least one, possibly two hardbreaks. let is_semi = match self.s.last_token() { - pp::String(s, _) => ";" == s.as_slice(), + pp::String(s, _) => ";" == s, _ => false }; if is_semi || self.is_begin() || self.is_end() { From 53b479c1953216733e02120d136b2e99e368cc8e Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 15:03:37 -0500 Subject: [PATCH 18/35] libterm: remove unnecessary `as_slice()` calls --- src/libterm/terminfo/mod.rs | 2 +- src/libterm/terminfo/parm.rs | 3 +-- src/libterm/terminfo/parser/compiled.rs | 3 +-- src/libterm/terminfo/searcher.rs | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index c1393767c8adc..65f8415835a36 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -183,7 +183,7 @@ impl TerminfoTerminal { let entry = open(term.as_slice()); if entry.is_err() { if os::getenv("MSYSCON").map_or(false, |s| { - "mintty.exe" == s.as_slice() + "mintty.exe" == s }) { // msys terminal return Some(box TerminfoTerminal {out: out, diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index d644542db0732..3a9d8619c3195 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -529,8 +529,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,String> { } } FormatHEX => { - s = s.as_slice() - .to_ascii() + s = s.to_ascii() .iter() .map(|b| b.to_uppercase().as_byte()) .collect(); diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index 9eb7216fba0bf..9b5e6f5cc9f6f 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -218,8 +218,7 @@ pub fn parse(file: &mut io::Reader, longnames: bool) Err(_) => return Err("input not utf-8".to_string()), }; - let term_names: Vec = names_str.as_slice() - .split('|') + let term_names: Vec = names_str.split('|') .map(|s| s.to_string()) .collect(); diff --git a/src/libterm/terminfo/searcher.rs b/src/libterm/terminfo/searcher.rs index 94e234291af98..2c1d76c7a405e 100644 --- a/src/libterm/terminfo/searcher.rs +++ b/src/libterm/terminfo/searcher.rs @@ -37,7 +37,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option> { dirs_to_search.push(homedir.unwrap().join(".terminfo")) } match getenv("TERMINFO_DIRS") { - Some(dirs) => for i in dirs.as_slice().split(':') { + Some(dirs) => for i in dirs.split(':') { if i == "" { dirs_to_search.push(Path::new("/usr/share/terminfo")); } else { From a0621f8eba169780c592916eeaf2855c69541f4b Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 15:06:09 -0500 Subject: [PATCH 19/35] libtest: remove unnecessary `as_slice()` calls --- src/libtest/lib.rs | 6 +++--- src/libtest/stats.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index c943d8706e55b..184195b988ae4 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -471,7 +471,7 @@ pub fn opt_shard(maybestr: Option) -> Option<(uint,uint)> { match maybestr { None => None, Some(s) => { - let mut it = s.as_slice().split('.'); + let mut it = s.split('.'); match (it.next().and_then(from_str::), it.next().and_then(from_str::), it.next()) { (Some(a), Some(b), None) => { @@ -934,8 +934,8 @@ fn should_sort_failures_before_printing_them() { Pretty(_) => unreachable!() }; - let apos = s.as_slice().find_str("a").unwrap(); - let bpos = s.as_slice().find_str("b").unwrap(); + let apos = s.find_str("a").unwrap(); + let bpos = s.find_str("b").unwrap(); assert!(apos < bpos); } diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index c157fb10bd4a7..f9e6907f0e880 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -250,7 +250,7 @@ impl Stats for [T] { // This constant is derived by smarter statistics brains than me, but it is // consistent with how R and other packages treat the MAD. let number = FromPrimitive::from_f64(1.4826).unwrap(); - abs_devs.as_slice().median() * number + abs_devs.median() * number } fn median_abs_dev_pct(&self) -> T { From 5a240588895b733f4e41fb8f9cb0a3d2f80b1e87 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 16:44:57 -0500 Subject: [PATCH 20/35] libcollections: remove unnecessary `as_mut_slice()` calls --- src/libcollections/binary_heap.rs | 2 +- src/libcollections/btree/node.rs | 16 +++++++-------- src/libcollections/slice.rs | 34 +++++++++++++++---------------- src/libcollections/vec.rs | 12 +++++------ 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 53d20aab24d61..e321ef16f66b5 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -485,7 +485,7 @@ impl BinaryHeap { let mut end = q.len(); while end > 1 { end -= 1; - q.data.as_mut_slice().swap(0, end); + q.data.swap(0, end); q.siftdown_range(0, end) } q.into_vec() diff --git a/src/libcollections/btree/node.rs b/src/libcollections/btree/node.rs index 2c681b6b1d354..3f53bad6518f2 100644 --- a/src/libcollections/btree/node.rs +++ b/src/libcollections/btree/node.rs @@ -158,13 +158,13 @@ impl Node { /// Swap the given key-value pair with the key-value pair stored in the node's index, /// without checking bounds. pub unsafe fn unsafe_swap(&mut self, index: uint, key: &mut K, val: &mut V) { - mem::swap(self.keys.as_mut_slice().unsafe_mut(index), key); - mem::swap(self.vals.as_mut_slice().unsafe_mut(index), val); + mem::swap(self.keys.unsafe_mut(index), key); + mem::swap(self.vals.unsafe_mut(index), val); } /// Get the node's key mutably without any bounds checks. pub unsafe fn unsafe_key_mut(&mut self, index: uint) -> &mut K { - self.keys.as_mut_slice().unsafe_mut(index) + self.keys.unsafe_mut(index) } /// Get the node's value at the given index @@ -189,12 +189,12 @@ impl Node { /// Get the node's edge mutably at the given index pub fn edge_mut(&mut self, index: uint) -> Option<&mut Node> { - self.edges.as_mut_slice().get_mut(index) + self.edges.get_mut(index) } /// Get the node's edge mutably without any bounds checks. pub unsafe fn unsafe_edge_mut(&mut self, index: uint) -> &mut Node { - self.edges.as_mut_slice().unsafe_mut(index) + self.edges.unsafe_mut(index) } /// Pop an edge off the end of the node @@ -292,8 +292,8 @@ impl Node { pub fn iter_mut<'a>(&'a mut self) -> MutTraversal<'a, K, V> { let is_leaf = self.is_leaf(); MutTraversal { - elems: self.keys.iter().zip(self.vals.as_mut_slice().iter_mut()), - edges: self.edges.as_mut_slice().iter_mut(), + elems: self.keys.iter().zip(self.vals.iter_mut()), + edges: self.edges.iter_mut(), head_is_edge: true, tail_is_edge: true, has_edges: !is_leaf, @@ -478,7 +478,7 @@ fn split(left: &mut Vec) -> Vec { let mut right = Vec::with_capacity(left.capacity()); unsafe { let left_ptr = left.unsafe_get(left_len) as *const _; - let right_ptr = right.as_mut_slice().as_mut_ptr(); + let right_ptr = right.as_mut_ptr(); ptr::copy_nonoverlapping_memory(right_ptr, left_ptr, right_len); left.set_len(left_len); right.set_len(right_len); diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 57e16fd7454ff..9417cc3e59479 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -201,7 +201,7 @@ impl Iterator<(uint, uint)> for ElementSwaps { match max { Some((i, sd)) => { let j = new_pos(i, sd.dir); - self.sdir.as_mut_slice().swap(i, j); + self.sdir.swap(i, j); // Swap the direction of each larger SizeDirection for x in self.sdir.iter_mut() { @@ -256,7 +256,7 @@ impl Iterator> for Permutations { Some((0,0)) => Some(self.v.clone()), Some((a, b)) => { let elt = self.v.clone(); - self.v.as_mut_slice().swap(a, b); + self.v.swap(a, b); Some(elt) } } @@ -779,11 +779,11 @@ mod tests { #[test] fn test_head_mut() { let mut a = vec![]; - assert_eq!(a.as_mut_slice().head_mut(), None); + assert_eq!(a.head_mut(), None); a = vec![11i]; - assert_eq!(*a.as_mut_slice().head_mut().unwrap(), 11); + assert_eq!(*a.head_mut().unwrap(), 11); a = vec![11i, 12]; - assert_eq!(*a.as_mut_slice().head_mut().unwrap(), 11); + assert_eq!(*a.head_mut().unwrap(), 11); } #[test] @@ -800,10 +800,10 @@ mod tests { fn test_tail_mut() { let mut a = vec![11i]; let b: &mut [int] = &mut []; - assert!(a.as_mut_slice().tail_mut() == b); + assert!(a.tail_mut() == b); a = vec![11i, 12]; let b: &mut [int] = &mut [12]; - assert!(a.as_mut_slice().tail_mut() == b); + assert!(a.tail_mut() == b); } #[test] @@ -817,7 +817,7 @@ mod tests { #[should_fail] fn test_tail_mut_empty() { let mut a: Vec = vec![]; - a.as_mut_slice().tail_mut(); + a.tail_mut(); } #[test] @@ -834,10 +834,10 @@ mod tests { fn test_init_mut() { let mut a = vec![11i]; let b: &mut [int] = &mut []; - assert!(a.as_mut_slice().init_mut() == b); + assert!(a.init_mut() == b); a = vec![11i, 12]; let b: &mut [int] = &mut [11]; - assert!(a.as_mut_slice().init_mut() == b); + assert!(a.init_mut() == b); } #[test] @@ -851,7 +851,7 @@ mod tests { #[should_fail] fn test_init_mut_empty() { let mut a: Vec = vec![]; - a.as_mut_slice().init_mut(); + a.init_mut(); } #[test] @@ -867,11 +867,11 @@ mod tests { #[test] fn test_last_mut() { let mut a = vec![]; - assert_eq!(a.as_mut_slice().last_mut(), None); + assert_eq!(a.last_mut(), None); a = vec![11i]; - assert_eq!(*a.as_mut_slice().last_mut().unwrap(), 11); + assert_eq!(*a.last_mut().unwrap(), 11); a = vec![11i, 12]; - assert_eq!(*a.as_mut_slice().last_mut().unwrap(), 12); + assert_eq!(*a.last_mut().unwrap(), 12); } #[test] @@ -1299,13 +1299,13 @@ mod tests { .collect::>(); let mut v1 = v.clone(); - v.as_mut_slice().sort(); + v.sort(); assert!(v.as_slice().windows(2).all(|w| w[0] <= w[1])); - v1.as_mut_slice().sort_by(|a, b| a.cmp(b)); + v1.sort_by(|a, b| a.cmp(b)); assert!(v1.as_slice().windows(2).all(|w| w[0] <= w[1])); - v1.as_mut_slice().sort_by(|a, b| b.cmp(a)); + v1.sort_by(|a, b| b.cmp(a)); assert!(v1.as_slice().windows(2).all(|w| w[0] >= w[1])); } } diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index e2411ced632af..c77ef86697ba4 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -211,7 +211,7 @@ impl Vec { let mut xs = Vec::with_capacity(length); while xs.len < length { let len = xs.len; - ptr::write(xs.as_mut_slice().unsafe_mut(len), op(len)); + ptr::write(xs.unsafe_mut(len), op(len)); xs.len += 1; } xs @@ -328,7 +328,7 @@ impl Vec { let mut xs = Vec::with_capacity(length); while xs.len < length { let len = xs.len; - ptr::write(xs.as_mut_slice().unsafe_mut(len), + ptr::write(xs.unsafe_mut(len), value.clone()); xs.len += 1; } @@ -361,7 +361,7 @@ impl Vec { // during the loop can prevent this optimisation. unsafe { ptr::write( - self.as_mut_slice().unsafe_mut(len), + self.unsafe_mut(len), other.unsafe_get(i).clone()); self.set_len(len + 1); } @@ -896,7 +896,7 @@ impl Vec { pub fn swap_remove(&mut self, index: uint) -> Option { let length = self.len(); if length > 0 && index < length - 1 { - self.as_mut_slice().swap(index, length - 1); + self.swap(index, length - 1); } else if index >= length { return None } @@ -1231,7 +1231,7 @@ impl Vec { if ln < 1 { return; } // Avoid bounds checks by using unsafe pointers. - let p = self.as_mut_slice().as_mut_ptr(); + let p = self.as_mut_ptr(); let mut r = 1; let mut w = 1; @@ -1293,7 +1293,7 @@ impl Drop for Vec { // zeroed (when moving out, because of #[unsafe_no_drop_flag]). if self.cap != 0 { unsafe { - for x in self.as_mut_slice().iter() { + for x in self.iter() { ptr::read(x); } dealloc(self.ptr, self.cap) From d64fd22c71b8aac82999919f31254359d81ef6ba Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 16:47:48 -0500 Subject: [PATCH 21/35] librustc: remove unnecessary `as_mut_slice` calls --- src/librustc/metadata/cstore.rs | 2 +- src/librustc/session/config.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index 07a8888c531cf..f93a1699e182d 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -172,7 +172,7 @@ impl CStore { for (&num, _) in self.metas.borrow().iter() { visit(self, num, &mut ordering); } - ordering.as_mut_slice().reverse(); + ordering.reverse(); let mut libs = self.used_crate_sources.borrow() .iter() .map(|src| (src.cnum, match prefer { diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 8701248d1f58e..981b58a3b7be1 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -764,7 +764,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { } } }; - output_types.as_mut_slice().sort(); + output_types.sort(); output_types.dedup(); if output_types.len() == 0 { output_types.push(OutputTypeExe); From a0a354ff220d1c49331bb40f3b1166b24c1df2f7 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 16:49:02 -0500 Subject: [PATCH 22/35] librustc_trans: remove unnecessary `as_mut_slice` calls --- src/librustc_driver/driver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 437b0257a9759..f3d76a8f12f1f 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -682,7 +682,7 @@ pub fn collect_crate_types(session: &Session, if base.len() == 0 { base.push(link::default_output_for_target(session)); } - base.as_mut_slice().sort(); + base.sort(); base.dedup(); } From 517298120778efc4a6cc0413528d070fdcd888b4 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 16:49:29 -0500 Subject: [PATCH 23/35] librustdoc: remove unnecessary `as_mut_slice` calls --- src/librustdoc/html/render.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 79ab452dba626..dab25c3b2ee59 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1261,7 +1261,7 @@ impl Context { } for (_, items) in map.iter_mut() { - items.as_mut_slice().sort(); + items.sort(); } return map; } From 6132a90788bb60fdd33f037b00e9227f7f26f655 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 16:50:34 -0500 Subject: [PATCH 24/35] libstd: remove unnecessary `as_mut_slice` calls --- src/libstd/sys/unix/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 4b47b768d600c..490ee36d9fa5f 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -201,7 +201,7 @@ pub fn readdir(p: &Path) -> IoResult> { let size = unsafe { rust_dirent_t_size() }; let mut buf = Vec::::with_capacity(size as uint); - let ptr = buf.as_mut_slice().as_mut_ptr() as *mut dirent_t; + let ptr = buf.as_mut_ptr() as *mut dirent_t; let p = p.to_c_str(); let dir_ptr = unsafe {opendir(p.as_ptr())}; From 976660f3f73a2dba68695fce1b697f7694af0a23 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 19:00:21 -0500 Subject: [PATCH 25/35] libtest: remove unnecessary `as_mut_slice()` calls --- src/libtest/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 184195b988ae4..6e202983ad8cc 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -706,7 +706,7 @@ impl ConsoleTestState { } try!(self.write_plain("\nfailures:\n")); - failures.as_mut_slice().sort(); + failures.sort(); for name in failures.iter() { try!(self.write_plain(format!(" {}\n", name.as_slice()).as_slice())); From 98ae63753bc6c2efe1c8ed50d45e665db686cde7 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 19:09:59 -0500 Subject: [PATCH 26/35] libcollections: remove unnecessary `to_string()` calls --- src/libcollections/bit.rs | 2 +- src/libcollections/btree/set.rs | 4 ++-- src/libcollections/slice.rs | 16 ++++++++-------- src/libcollections/str.rs | 8 ++++---- src/libcollections/string.rs | 24 ++++++++++++------------ src/libcollections/tree/map.rs | 4 ++-- src/libcollections/tree/set.rs | 4 ++-- src/libcollections/trie/map.rs | 4 ++-- src/libcollections/trie/set.rs | 4 ++-- src/libcollections/vec_map.rs | 2 +- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 953e432fd4a75..ad5732c47a891 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -2660,7 +2660,7 @@ mod tests { s.insert(10); s.insert(50); s.insert(2); - assert_eq!("{1, 2, 10, 50}".to_string(), s.to_string()); + assert_eq!("{1, 2, 10, 50}", s.to_string()); } fn rng() -> rand::IsaacRng { diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 64ae4f6a50867..bacbe98ad612f 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -580,7 +580,7 @@ mod test { let set_str = format!("{}", set); - assert!(set_str == "{1, 2}".to_string()); - assert_eq!(format!("{}", empty), "{}".to_string()); + assert!(set_str == "{1, 2}"); + assert_eq!(format!("{}", empty), "{}"); } } diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 9417cc3e59479..03b8ea8f20fa5 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1838,20 +1838,20 @@ mod tests { }) ) let empty: Vec = vec![]; - test_show_vec!(empty, "[]".to_string()); - test_show_vec!(vec![1i], "[1]".to_string()); - test_show_vec!(vec![1i, 2, 3], "[1, 2, 3]".to_string()); + test_show_vec!(empty, "[]"); + test_show_vec!(vec![1i], "[1]"); + test_show_vec!(vec![1i, 2, 3], "[1, 2, 3]"); test_show_vec!(vec![vec![], vec![1u], vec![1u, 1u]], - "[[], [1], [1, 1]]".to_string()); + "[[], [1], [1, 1]]"); let empty_mut: &mut [int] = &mut[]; - test_show_vec!(empty_mut, "[]".to_string()); + test_show_vec!(empty_mut, "[]"); let v: &mut[int] = &mut[1]; - test_show_vec!(v, "[1]".to_string()); + test_show_vec!(v, "[1]"); let v: &mut[int] = &mut[1, 2, 3]; - test_show_vec!(v, "[1, 2, 3]".to_string()); + test_show_vec!(v, "[1, 2, 3]"); let v: &mut [&mut[uint]] = &mut[&mut[], &mut[1u], &mut[1u, 1u]]; - test_show_vec!(v, "[[], [1], [1, 1]]".to_string()); + test_show_vec!(v, "[[], [1], [1, 1]]"); } #[test] diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 6e26962950ba2..0c41a850ac3f8 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1831,7 +1831,7 @@ mod tests { fn test_nfd_chars() { macro_rules! t { ($input: expr, $expected: expr) => { - assert_eq!($input.nfd_chars().collect::(), $expected.into_string()); + assert_eq!($input.nfd_chars().collect::(), $expected); } } t!("abc", "abc"); @@ -1850,7 +1850,7 @@ mod tests { fn test_nfkd_chars() { macro_rules! t { ($input: expr, $expected: expr) => { - assert_eq!($input.nfkd_chars().collect::(), $expected.into_string()); + assert_eq!($input.nfkd_chars().collect::(), $expected); } } t!("abc", "abc"); @@ -1869,7 +1869,7 @@ mod tests { fn test_nfc_chars() { macro_rules! t { ($input: expr, $expected: expr) => { - assert_eq!($input.nfc_chars().collect::(), $expected.into_string()); + assert_eq!($input.nfc_chars().collect::(), $expected); } } t!("abc", "abc"); @@ -1889,7 +1889,7 @@ mod tests { fn test_nfkc_chars() { macro_rules! t { ($input: expr, $expected: expr) => { - assert_eq!($input.nfkc_chars().collect::(), $expected.into_string()); + assert_eq!($input.nfkc_chars().collect::(), $expected); } } t!("abc", "abc"); diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index a7545d0696027..571f3fa468589 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1287,24 +1287,24 @@ mod tests { #[test] fn test_simple_types() { - assert_eq!(1i.to_string(), "1".to_string()); - assert_eq!((-1i).to_string(), "-1".to_string()); - assert_eq!(200u.to_string(), "200".to_string()); - assert_eq!(2u8.to_string(), "2".to_string()); - assert_eq!(true.to_string(), "true".to_string()); - assert_eq!(false.to_string(), "false".to_string()); - assert_eq!(().to_string(), "()".to_string()); - assert_eq!(("hi".to_string()).to_string(), "hi".to_string()); + assert_eq!(1i.to_string(), "1"); + assert_eq!((-1i).to_string(), "-1"); + assert_eq!(200u.to_string(), "200"); + assert_eq!(2u8.to_string(), "2"); + assert_eq!(true.to_string(), "true"); + assert_eq!(false.to_string(), "false"); + assert_eq!(().to_string(), "()"); + assert_eq!(("hi".to_string()).to_string(), "hi"); } #[test] fn test_vectors() { let x: Vec = vec![]; - assert_eq!(x.to_string(), "[]".to_string()); - assert_eq!((vec![1i]).to_string(), "[1]".to_string()); - assert_eq!((vec![1i, 2, 3]).to_string(), "[1, 2, 3]".to_string()); + assert_eq!(x.to_string(), "[]"); + assert_eq!((vec![1i]).to_string(), "[1]"); + assert_eq!((vec![1i, 2, 3]).to_string(), "[1, 2, 3]"); assert!((vec![vec![], vec![1i], vec![1i, 1]]).to_string() == - "[[], [1], [1, 1]]".to_string()); + "[[], [1], [1, 1]]"); } #[bench] diff --git a/src/libcollections/tree/map.rs b/src/libcollections/tree/map.rs index 119268c27eeac..3818be5a19791 100644 --- a/src/libcollections/tree/map.rs +++ b/src/libcollections/tree/map.rs @@ -1735,8 +1735,8 @@ mod test_treemap { let map_str = format!("{}", map); - assert!(map_str == "{1: 2, 3: 4}".to_string()); - assert_eq!(format!("{}", empty), "{}".to_string()); + assert!(map_str == "{1: 2, 3: 4}"); + assert_eq!(format!("{}", empty), "{}"); } #[test] diff --git a/src/libcollections/tree/set.rs b/src/libcollections/tree/set.rs index 6988b929df689..bdb33f7049913 100644 --- a/src/libcollections/tree/set.rs +++ b/src/libcollections/tree/set.rs @@ -979,7 +979,7 @@ mod test { let set_str = format!("{}", set); - assert!(set_str == "{1, 2}".to_string()); - assert_eq!(format!("{}", empty), "{}".to_string()); + assert!(set_str == "{1, 2}"); + assert_eq!(format!("{}", empty), "{}"); } } diff --git a/src/libcollections/trie/map.rs b/src/libcollections/trie/map.rs index 672ddab4d87e0..6491c9a569dc6 100644 --- a/src/libcollections/trie/map.rs +++ b/src/libcollections/trie/map.rs @@ -1605,8 +1605,8 @@ mod test { let map_str = format!("{}", map); - assert!(map_str == "{1: a, 2: b}".to_string()); - assert_eq!(format!("{}", empty), "{}".to_string()); + assert!(map_str == "{1: a, 2: b}"); + assert_eq!(format!("{}", empty), "{}"); } #[test] diff --git a/src/libcollections/trie/set.rs b/src/libcollections/trie/set.rs index 1b3657943da6d..436da51174284 100644 --- a/src/libcollections/trie/set.rs +++ b/src/libcollections/trie/set.rs @@ -696,8 +696,8 @@ mod test { let set_str = format!("{}", set); - assert!(set_str == "{1, 2}".to_string()); - assert_eq!(format!("{}", empty), "{}".to_string()); + assert!(set_str == "{1, 2}"); + assert_eq!(format!("{}", empty), "{}"); } #[test] diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 3be662c071c16..97b80108d766e 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -871,7 +871,7 @@ mod test_map { let map_str = map.to_string(); assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}"); - assert_eq!(format!("{}", empty), "{}".to_string()); + assert_eq!(format!("{}", empty), "{}"); } #[test] From 8379d722933eff4831fc38e158a7238a9e2d8984 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 19:18:54 -0500 Subject: [PATCH 27/35] libgetopts: remove unnecessary `to_string()` calls --- src/libgetopts/lib.rs | 78 +++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 19af3f595b286..daf0f7f3818d7 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -962,9 +962,9 @@ mod tests { match rs { Ok(ref m) => { assert!(m.opt_present("test")); - assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("test").unwrap(), "20"); assert!(m.opt_present("t")); - assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("t").unwrap(), "20"); } _ => { panic!("test_reqopt failed (long arg)"); } } @@ -972,9 +972,9 @@ mod tests { match getopts(short_args.as_slice(), opts.as_slice()) { Ok(ref m) => { assert!((m.opt_present("test"))); - assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("test").unwrap(), "20"); assert!((m.opt_present("t"))); - assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("t").unwrap(), "20"); } _ => { panic!("test_reqopt failed (short arg)"); } } @@ -1027,9 +1027,9 @@ mod tests { match rs { Ok(ref m) => { assert!(m.opt_present("test")); - assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("test").unwrap(), "20"); assert!((m.opt_present("t"))); - assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("t").unwrap(), "20"); } _ => panic!() } @@ -1037,9 +1037,9 @@ mod tests { match getopts(short_args.as_slice(), opts.as_slice()) { Ok(ref m) => { assert!((m.opt_present("test"))); - assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("test").unwrap(), "20"); assert!((m.opt_present("t"))); - assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("t").unwrap(), "20"); } _ => panic!() } @@ -1154,7 +1154,7 @@ mod tests { Ok(ref m) => { // The next variable after the flag is just a free argument - assert!(m.free[0] == "20".to_string()); + assert!(m.free[0] == "20"); } _ => panic!() } @@ -1250,9 +1250,9 @@ mod tests { match rs { Ok(ref m) => { assert!((m.opt_present("test"))); - assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("test").unwrap(), "20"); assert!((m.opt_present("t"))); - assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("t").unwrap(), "20"); } _ => panic!() } @@ -1260,9 +1260,9 @@ mod tests { match getopts(short_args.as_slice(), opts.as_slice()) { Ok(ref m) => { assert!((m.opt_present("test"))); - assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("test").unwrap(), "20"); assert!((m.opt_present("t"))); - assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("t").unwrap(), "20"); } _ => panic!() } @@ -1306,12 +1306,12 @@ mod tests { match rs { Ok(ref m) => { assert!(m.opt_present("test")); - assert_eq!(m.opt_str("test").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("test").unwrap(), "20"); assert!(m.opt_present("t")); - assert_eq!(m.opt_str("t").unwrap(), "20".to_string()); + assert_eq!(m.opt_str("t").unwrap(), "20"); let pair = m.opt_strs("test"); - assert!(pair[0] == "20".to_string()); - assert!(pair[1] == "30".to_string()); + assert!(pair[0] == "20"); + assert!(pair[1] == "30"); } _ => panic!() } @@ -1363,19 +1363,19 @@ mod tests { let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { - assert!(m.free[0] == "prog".to_string()); - assert!(m.free[1] == "free1".to_string()); - assert_eq!(m.opt_str("s").unwrap(), "20".to_string()); - assert!(m.free[2] == "free2".to_string()); + assert!(m.free[0] == "prog"); + assert!(m.free[1] == "free1"); + assert_eq!(m.opt_str("s").unwrap(), "20"); + assert!(m.free[2] == "free2"); assert!((m.opt_present("flag"))); - assert_eq!(m.opt_str("long").unwrap(), "30".to_string()); + assert_eq!(m.opt_str("long").unwrap(), "30"); assert!((m.opt_present("f"))); let pair = m.opt_strs("m"); - assert!(pair[0] == "40".to_string()); - assert!(pair[1] == "50".to_string()); + assert!(pair[0] == "40"); + assert!(pair[1] == "50"); let pair = m.opt_strs("n"); - assert!(pair[0] == "-A B".to_string()); - assert!(pair[1] == "-60 70".to_string()); + assert!(pair[0] == "-A B"); + assert!(pair[1] == "-60 70"); assert!((!m.opt_present("notpresent"))); } _ => panic!() @@ -1401,11 +1401,11 @@ mod tests { assert!(!matches_single.opts_present(&["thing".to_string()])); assert!(!matches_single.opts_present(&[])); - assert_eq!(matches_single.opts_str(&["e".to_string()]).unwrap(), "foo".to_string()); + assert_eq!(matches_single.opts_str(&["e".to_string()]).unwrap(), "foo"); assert_eq!(matches_single.opts_str(&["e".to_string(), "encrypt".to_string()]).unwrap(), - "foo".to_string()); + "foo"); assert_eq!(matches_single.opts_str(&["encrypt".to_string(), "e".to_string()]).unwrap(), - "foo".to_string()); + "foo"); let args_both = vec!("-e".to_string(), "foo".to_string(), "--encrypt".to_string(), "foo".to_string()); @@ -1422,12 +1422,12 @@ mod tests { assert!(!matches_both.opts_present(&["thing".to_string()])); assert!(!matches_both.opts_present(&[])); - assert_eq!(matches_both.opts_str(&["e".to_string()]).unwrap(), "foo".to_string()); - assert_eq!(matches_both.opts_str(&["encrypt".to_string()]).unwrap(), "foo".to_string()); + assert_eq!(matches_both.opts_str(&["e".to_string()]).unwrap(), "foo"); + assert_eq!(matches_both.opts_str(&["encrypt".to_string()]).unwrap(), "foo"); assert_eq!(matches_both.opts_str(&["e".to_string(), "encrypt".to_string()]).unwrap(), - "foo".to_string()); + "foo"); assert_eq!(matches_both.opts_str(&["encrypt".to_string(), "e".to_string()]).unwrap(), - "foo".to_string()); + "foo"); } #[test] @@ -1440,9 +1440,9 @@ mod tests { result::Err(_) => panic!() }; assert!(matches.opts_present(&["L".to_string()])); - assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "foo".to_string()); + assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "foo"); assert!(matches.opts_present(&["M".to_string()])); - assert_eq!(matches.opts_str(&["M".to_string()]).unwrap(), ".".to_string()); + assert_eq!(matches.opts_str(&["M".to_string()]).unwrap(), "."); } @@ -1456,7 +1456,7 @@ mod tests { result::Err(e) => panic!( "{}", e ) }; assert!(matches.opts_present(&["L".to_string()])); - assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "verbose".to_string()); + assert_eq!(matches.opts_str(&["L".to_string()]).unwrap(), "verbose"); assert!(matches.opts_present(&["v".to_string()])); assert_eq!(3, matches.opt_count("v")); } @@ -1510,7 +1510,7 @@ Options: -k --kiwi Desc -p [VAL] Desc -l VAL Desc -".to_string(); +"; let generated_usage = usage("Usage: fruits", optgroups.as_slice()); @@ -1537,7 +1537,7 @@ Options: -k --kiwi This is a long description which won't be wrapped..+.. -a --apple This is a long description which _will_ be wrapped..+.. -".to_string(); +"; let usage = usage("Usage: fruits", optgroups.as_slice()); @@ -1563,7 +1563,7 @@ Options: -a --apple This “description” has some characters that could confuse the line wrapping; an apple costs 0.51€ in some parts of Europe. -".to_string(); +"; let usage = usage("Usage: fruits", optgroups.as_slice()); From 71d8d578c6050fcef42caecb61b9d1bcba7716af Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 19:23:53 -0500 Subject: [PATCH 28/35] librustc_back: remove unnecessary `to_string()` calls --- src/librustc_back/rpath.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_back/rpath.rs b/src/librustc_back/rpath.rs index ea691b85f6c27..a90b49ba101fa 100644 --- a/src/librustc_back/rpath.rs +++ b/src/librustc_back/rpath.rs @@ -145,8 +145,8 @@ mod test { "path2".to_string() ]); assert_eq!(flags, - vec!("-Wl,-rpath,path1".to_string(), - "-Wl,-rpath,path2".to_string())); + ["-Wl,-rpath,path1", + "-Wl,-rpath,path2"]); } #[test] From ba01ea3730025028affbf4ce56f29621861779c6 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 19:36:41 -0500 Subject: [PATCH 29/35] libserialize: remove unnecessary `to_string()` calls --- src/libserialize/base64.rs | 24 ++++----- src/libserialize/hex.rs | 2 +- src/libserialize/json.rs | 100 ++++++++++++++++++------------------- 3 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index 8efb8e5b78d50..c8ec1700a1dae 100644 --- a/src/libserialize/base64.rs +++ b/src/libserialize/base64.rs @@ -286,13 +286,13 @@ mod tests { #[test] fn test_to_base64_basic() { - assert_eq!("".as_bytes().to_base64(STANDARD), "".to_string()); - assert_eq!("f".as_bytes().to_base64(STANDARD), "Zg==".to_string()); - assert_eq!("fo".as_bytes().to_base64(STANDARD), "Zm8=".to_string()); - assert_eq!("foo".as_bytes().to_base64(STANDARD), "Zm9v".to_string()); - assert_eq!("foob".as_bytes().to_base64(STANDARD), "Zm9vYg==".to_string()); - assert_eq!("fooba".as_bytes().to_base64(STANDARD), "Zm9vYmE=".to_string()); - assert_eq!("foobar".as_bytes().to_base64(STANDARD), "Zm9vYmFy".to_string()); + assert_eq!("".as_bytes().to_base64(STANDARD), ""); + assert_eq!("f".as_bytes().to_base64(STANDARD), "Zg=="); + assert_eq!("fo".as_bytes().to_base64(STANDARD), "Zm8="); + assert_eq!("foo".as_bytes().to_base64(STANDARD), "Zm9v"); + assert_eq!("foob".as_bytes().to_base64(STANDARD), "Zm9vYg=="); + assert_eq!("fooba".as_bytes().to_base64(STANDARD), "Zm9vYmE="); + assert_eq!("foobar".as_bytes().to_base64(STANDARD), "Zm9vYmFy"); } #[test] @@ -301,19 +301,19 @@ mod tests { .contains("\r\n")); assert_eq!("foobar".as_bytes().to_base64(Config {line_length: Some(4), ..STANDARD}), - "Zm9v\r\nYmFy".to_string()); + "Zm9v\r\nYmFy"); } #[test] fn test_to_base64_padding() { - assert_eq!("f".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zg".to_string()); - assert_eq!("fo".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zm8".to_string()); + assert_eq!("f".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zg"); + assert_eq!("fo".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zm8"); } #[test] fn test_to_base64_url_safe() { - assert_eq!([251, 255].to_base64(URL_SAFE), "-_8".to_string()); - assert_eq!([251, 255].to_base64(STANDARD), "+/8=".to_string()); + assert_eq!([251, 255].to_base64(URL_SAFE), "-_8"); + assert_eq!([251, 255].to_base64(STANDARD), "+/8="); } #[test] diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index 443a31f7493f2..4c20f72cac5b1 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -158,7 +158,7 @@ mod tests { #[test] pub fn test_to_hex() { - assert_eq!("foobar".as_bytes().to_hex(), "666f6f626172".to_string()); + assert_eq!("foobar".as_bytes().to_hex(), "666f6f626172"); } #[test] diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index abf2341a76cbe..248d78236ad4b 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -2486,76 +2486,76 @@ mod tests { #[test] fn test_write_null() { - assert_eq!(Null.to_string().into_string(), "null".to_string()); - assert_eq!(Null.to_pretty_str().into_string(), "null".to_string()); + assert_eq!(Null.to_string().into_string(), "null"); + assert_eq!(Null.to_pretty_str().into_string(), "null"); } #[test] fn test_write_i64() { - assert_eq!(U64(0).to_string().into_string(), "0".to_string()); - assert_eq!(U64(0).to_pretty_str().into_string(), "0".to_string()); + assert_eq!(U64(0).to_string().into_string(), "0"); + assert_eq!(U64(0).to_pretty_str().into_string(), "0"); - assert_eq!(U64(1234).to_string().into_string(), "1234".to_string()); - assert_eq!(U64(1234).to_pretty_str().into_string(), "1234".to_string()); + assert_eq!(U64(1234).to_string().into_string(), "1234"); + assert_eq!(U64(1234).to_pretty_str().into_string(), "1234"); - assert_eq!(I64(-5678).to_string().into_string(), "-5678".to_string()); - assert_eq!(I64(-5678).to_pretty_str().into_string(), "-5678".to_string()); + assert_eq!(I64(-5678).to_string().into_string(), "-5678"); + assert_eq!(I64(-5678).to_pretty_str().into_string(), "-5678"); } #[test] fn test_write_f64() { - assert_eq!(F64(3.0).to_string().into_string(), "3".to_string()); - assert_eq!(F64(3.0).to_pretty_str().into_string(), "3".to_string()); + assert_eq!(F64(3.0).to_string().into_string(), "3"); + assert_eq!(F64(3.0).to_pretty_str().into_string(), "3"); - assert_eq!(F64(3.1).to_string().into_string(), "3.1".to_string()); - assert_eq!(F64(3.1).to_pretty_str().into_string(), "3.1".to_string()); + assert_eq!(F64(3.1).to_string().into_string(), "3.1"); + assert_eq!(F64(3.1).to_pretty_str().into_string(), "3.1"); - assert_eq!(F64(-1.5).to_string().into_string(), "-1.5".to_string()); - assert_eq!(F64(-1.5).to_pretty_str().into_string(), "-1.5".to_string()); + assert_eq!(F64(-1.5).to_string().into_string(), "-1.5"); + assert_eq!(F64(-1.5).to_pretty_str().into_string(), "-1.5"); - assert_eq!(F64(0.5).to_string().into_string(), "0.5".to_string()); - assert_eq!(F64(0.5).to_pretty_str().into_string(), "0.5".to_string()); + assert_eq!(F64(0.5).to_string().into_string(), "0.5"); + assert_eq!(F64(0.5).to_pretty_str().into_string(), "0.5"); - assert_eq!(F64(f64::NAN).to_string().into_string(), "null".to_string()); - assert_eq!(F64(f64::NAN).to_pretty_str().into_string(), "null".to_string()); + assert_eq!(F64(f64::NAN).to_string().into_string(), "null"); + assert_eq!(F64(f64::NAN).to_pretty_str().into_string(), "null"); - assert_eq!(F64(f64::INFINITY).to_string().into_string(), "null".to_string()); - assert_eq!(F64(f64::INFINITY).to_pretty_str().into_string(), "null".to_string()); + assert_eq!(F64(f64::INFINITY).to_string().into_string(), "null"); + assert_eq!(F64(f64::INFINITY).to_pretty_str().into_string(), "null"); - assert_eq!(F64(f64::NEG_INFINITY).to_string().into_string(), "null".to_string()); - assert_eq!(F64(f64::NEG_INFINITY).to_pretty_str().into_string(), "null".to_string()); + assert_eq!(F64(f64::NEG_INFINITY).to_string().into_string(), "null"); + assert_eq!(F64(f64::NEG_INFINITY).to_pretty_str().into_string(), "null"); } #[test] fn test_write_str() { - assert_eq!(String("".to_string()).to_string().into_string(), "\"\"".to_string()); - assert_eq!(String("".to_string()).to_pretty_str().into_string(), "\"\"".to_string()); + assert_eq!(String("".to_string()).to_string().into_string(), "\"\""); + assert_eq!(String("".to_string()).to_pretty_str().into_string(), "\"\""); - assert_eq!(String("foo".to_string()).to_string().into_string(), "\"foo\"".to_string()); - assert_eq!(String("foo".to_string()).to_pretty_str().into_string(), "\"foo\"".to_string()); + assert_eq!(String("foo".to_string()).to_string().into_string(), "\"foo\""); + assert_eq!(String("foo".to_string()).to_pretty_str().into_string(), "\"foo\""); } #[test] fn test_write_bool() { - assert_eq!(Boolean(true).to_string().into_string(), "true".to_string()); - assert_eq!(Boolean(true).to_pretty_str().into_string(), "true".to_string()); + assert_eq!(Boolean(true).to_string().into_string(), "true"); + assert_eq!(Boolean(true).to_pretty_str().into_string(), "true"); - assert_eq!(Boolean(false).to_string().into_string(), "false".to_string()); - assert_eq!(Boolean(false).to_pretty_str().into_string(), "false".to_string()); + assert_eq!(Boolean(false).to_string().into_string(), "false"); + assert_eq!(Boolean(false).to_pretty_str().into_string(), "false"); } #[test] fn test_write_array() { - assert_eq!(Array(vec![]).to_string().into_string(), "[]".to_string()); - assert_eq!(Array(vec![]).to_pretty_str().into_string(), "[]".to_string()); + assert_eq!(Array(vec![]).to_string().into_string(), "[]"); + assert_eq!(Array(vec![]).to_pretty_str().into_string(), "[]"); - assert_eq!(Array(vec![Boolean(true)]).to_string().into_string(), "[true]".to_string()); + assert_eq!(Array(vec![Boolean(true)]).to_string().into_string(), "[true]"); assert_eq!( Array(vec![Boolean(true)]).to_pretty_str().into_string(), "\ [\n \ true\n\ - ]".to_string() + ]" ); let long_test_array = Array(vec![ @@ -2564,7 +2564,7 @@ mod tests { Array(vec![String("foo\nbar".to_string()), F64(3.5)])]); assert_eq!(long_test_array.to_string().into_string(), - "[false,null,[\"foo\\nbar\",3.5]]".to_string()); + "[false,null,[\"foo\\nbar\",3.5]]"); assert_eq!( long_test_array.to_pretty_str().into_string(), "\ @@ -2575,27 +2575,27 @@ mod tests { \"foo\\nbar\",\n \ 3.5\n \ ]\n\ - ]".to_string() + ]" ); } #[test] fn test_write_object() { - assert_eq!(mk_object(&[]).to_string().into_string(), "{}".to_string()); - assert_eq!(mk_object(&[]).to_pretty_str().into_string(), "{}".to_string()); + assert_eq!(mk_object(&[]).to_string().into_string(), "{}"); + assert_eq!(mk_object(&[]).to_pretty_str().into_string(), "{}"); assert_eq!( mk_object(&[ ("a".to_string(), Boolean(true)) ]).to_string().into_string(), - "{\"a\":true}".to_string() + "{\"a\":true}" ); assert_eq!( mk_object(&[("a".to_string(), Boolean(true))]).to_pretty_str(), "\ {\n \ \"a\": true\n\ - }".to_string() + }" ); let complex_obj = mk_object(&[ @@ -2612,7 +2612,7 @@ mod tests { {\"c\":\"\\f\\r\"},\ {\"d\":\"\"}\ ]\ - }".to_string() + }" ); assert_eq!( complex_obj.to_pretty_str().into_string(), @@ -2626,7 +2626,7 @@ mod tests { \"d\": \"\"\n \ }\n \ ]\n\ - }".to_string() + }" ); let a = mk_object(&[ @@ -2660,14 +2660,14 @@ mod tests { let mut encoder = Encoder::new(writer); animal.encode(&mut encoder).unwrap(); }), - "\"Dog\"".to_string() + "\"Dog\"" ); assert_eq!( with_str_writer(|writer| { let mut encoder = PrettyEncoder::new(writer); animal.encode(&mut encoder).unwrap(); }), - "\"Dog\"".to_string() + "\"Dog\"" ); let animal = Frog("Henry".to_string(), 349); @@ -2676,7 +2676,7 @@ mod tests { let mut encoder = Encoder::new(writer); animal.encode(&mut encoder).unwrap(); }), - "{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}".to_string() + "{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}" ); assert_eq!( with_str_writer(|writer| { @@ -2689,7 +2689,7 @@ mod tests { \"Henry\",\n \ 349\n \ ]\n\ - }".to_string() + }" ); } @@ -2700,14 +2700,14 @@ mod tests { let mut encoder = Encoder::new(writer); value.encode(&mut encoder).unwrap(); }); - assert_eq!(s, "\"jodhpurs\"".to_string()); + assert_eq!(s, "\"jodhpurs\""); let value = Some("jodhpurs".to_string()); let s = with_str_writer(|writer| { let mut encoder = PrettyEncoder::new(writer); value.encode(&mut encoder).unwrap(); }); - assert_eq!(s, "\"jodhpurs\"".to_string()); + assert_eq!(s, "\"jodhpurs\""); } #[test] @@ -2717,13 +2717,13 @@ mod tests { let mut encoder = Encoder::new(writer); value.encode(&mut encoder).unwrap(); }); - assert_eq!(s, "null".to_string()); + assert_eq!(s, "null"); let s = with_str_writer(|writer| { let mut encoder = Encoder::new(writer); value.encode(&mut encoder).unwrap(); }); - assert_eq!(s, "null".to_string()); + assert_eq!(s, "null"); } #[test] From c2da923fc95e29424a7dac1505d6e8ea50c49b9f Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 19:45:47 -0500 Subject: [PATCH 30/35] libstd: remove unnecessary `to_string()` calls --- src/libstd/ascii.rs | 42 ++++++++++++++--------------- src/libstd/collections/hash/map.rs | 4 +-- src/libstd/collections/hash/set.rs | 4 +-- src/libstd/collections/lru_cache.rs | 12 ++++----- src/libstd/io/mem.rs | 4 +-- src/libstd/io/mod.rs | 16 +++++------ src/libstd/io/net/ip.rs | 6 ++--- src/libstd/io/process.rs | 10 +++---- src/libstd/io/stdio.rs | 2 +- src/libstd/num/strconv.rs | 16 +++++------ src/libstd/num/uint_macros.rs | 16 +++++------ src/libstd/path/windows.rs | 4 +-- src/libstd/rt/backtrace.rs | 2 +- src/libstd/sync/future.rs | 12 ++++----- src/libstd/sys/windows/process.rs | 10 +++---- src/libstd/task.rs | 10 +++---- src/libstd/time/duration.rs | 22 +++++++-------- 17 files changed, 96 insertions(+), 96 deletions(-) diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index f31c694098f40..a03d946f40742 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -680,13 +680,13 @@ mod tests { assert_eq!(v.to_ascii(), b); assert_eq!("( ;".to_string().to_ascii(), b); - assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#".to_string()); - assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#".to_string()); + assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#"); + assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#"); - assert_eq!("".to_ascii().to_lowercase().into_string(), "".to_string()); - assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca".to_string()); + assert_eq!("".to_ascii().to_lowercase().into_string(), ""); + assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca"); let mixed = "abcDEFxyz:.;".to_ascii(); - assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;".to_string()); + assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;"); assert!("aBcDeF&?#".to_ascii().eq_ignore_case("AbCdEf&?#".to_ascii())); @@ -698,12 +698,12 @@ mod tests { #[test] fn test_ascii_vec_ng() { - assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#".to_string()); - assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#".to_string()); - assert_eq!("".to_ascii().to_lowercase().into_string(), "".to_string()); - assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca".to_string()); + assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#"); + assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#"); + assert_eq!("".to_ascii().to_lowercase().into_string(), ""); + assert_eq!("YMCA".to_ascii().to_lowercase().into_string(), "ymca"); let mixed = "abcDEFxyz:.;".to_ascii(); - assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;".to_string()); + assert_eq!(mixed.to_uppercase().into_string(), "ABCDEFXYZ:.;"); } #[test] @@ -720,8 +720,8 @@ mod tests { #[test] fn test_ascii_into_string() { - assert_eq!(vec2ascii![40, 32, 59].into_string(), "( ;".to_string()); - assert_eq!(vec2ascii!(40, 32, 59).into_string(), "( ;".to_string()); + assert_eq!(vec2ascii![40, 32, 59].into_string(), "( ;"); + assert_eq!(vec2ascii!(40, 32, 59).into_string(), "( ;"); } #[test] @@ -773,8 +773,8 @@ mod tests { #[test] fn test_to_ascii_upper() { - assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), "URL()URL()URL()üRL".to_string()); - assert_eq!("hıKß".to_ascii_upper(), "HıKß".to_string()); + assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), "URL()URL()URL()üRL"); + assert_eq!("hıKß".to_ascii_upper(), "HıKß"); let mut i = 0; while i <= 500 { @@ -788,9 +788,9 @@ mod tests { #[test] fn test_to_ascii_lower() { - assert_eq!("url()URL()uRl()Ürl".to_ascii_lower(), "url()url()url()Ürl".to_string()); + assert_eq!("url()URL()uRl()Ürl".to_ascii_lower(), "url()url()url()Ürl"); // Dotted capital I, Kelvin sign, Sharp S. - assert_eq!("HİKß".to_ascii_lower(), "hİKß".to_string()); + assert_eq!("HİKß".to_ascii_lower(), "hİKß"); let mut i = 0; while i <= 500 { @@ -806,7 +806,7 @@ mod tests { fn test_into_ascii_upper() { assert_eq!(("url()URL()uRl()ürl".to_string()).into_ascii_upper(), "URL()URL()URL()üRL".to_string()); - assert_eq!(("hıKß".to_string()).into_ascii_upper(), "HıKß".to_string()); + assert_eq!(("hıKß".to_string()).into_ascii_upper(), "HıKß"); let mut i = 0; while i <= 500 { @@ -821,9 +821,9 @@ mod tests { #[test] fn test_into_ascii_lower() { assert_eq!(("url()URL()uRl()Ürl".to_string()).into_ascii_lower(), - "url()url()url()Ürl".to_string()); + "url()url()url()Ürl"); // Dotted capital I, Kelvin sign, Sharp S. - assert_eq!(("HİKß".to_string()).into_ascii_lower(), "hİKß".to_string()); + assert_eq!(("HİKß".to_string()).into_ascii_lower(), "hİKß"); let mut i = 0; while i <= 500 { @@ -859,12 +859,12 @@ mod tests { #[test] fn test_to_string() { let s = Ascii{ chr: b't' }.to_string(); - assert_eq!(s, "t".to_string()); + assert_eq!(s, "t"); } #[test] fn test_show() { let c = Ascii { chr: b't' }; - assert_eq!(format!("{}", c), "t".to_string()); + assert_eq!(format!("{}", c), "t"); } } diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 1fb6279d004b5..ef7fe48b1adf8 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1903,8 +1903,8 @@ mod test_map { let map_str = format!("{}", map); - assert!(map_str == "{1: 2, 3: 4}".to_string() || map_str == "{3: 4, 1: 2}".to_string()); - assert_eq!(format!("{}", empty), "{}".to_string()); + assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}"); + assert_eq!(format!("{}", empty), "{}"); } #[test] diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 9c9f23369e562..ebf7a29ad3f93 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -862,7 +862,7 @@ mod test_set { let set_str = format!("{}", set); - assert!(set_str == "{1, 2}".to_string() || set_str == "{2, 1}".to_string()); - assert_eq!(format!("{}", empty), "{}".to_string()); + assert!(set_str == "{1, 2}" || set_str == "{2, 1}"); + assert_eq!(format!("{}", empty), "{}"); } } diff --git a/src/libstd/collections/lru_cache.rs b/src/libstd/collections/lru_cache.rs index 94bea37d18728..638ccdb111274 100644 --- a/src/libstd/collections/lru_cache.rs +++ b/src/libstd/collections/lru_cache.rs @@ -446,15 +446,15 @@ mod tests { cache.insert(1, 10); cache.insert(2, 20); cache.insert(3, 30); - assert_eq!(cache.to_string(), "{3: 30, 2: 20, 1: 10}".to_string()); + assert_eq!(cache.to_string(), "{3: 30, 2: 20, 1: 10}"); cache.insert(2, 22); - assert_eq!(cache.to_string(), "{2: 22, 3: 30, 1: 10}".to_string()); + assert_eq!(cache.to_string(), "{2: 22, 3: 30, 1: 10}"); cache.insert(6, 60); - assert_eq!(cache.to_string(), "{6: 60, 2: 22, 3: 30}".to_string()); + assert_eq!(cache.to_string(), "{6: 60, 2: 22, 3: 30}"); cache.get(&3); - assert_eq!(cache.to_string(), "{3: 30, 6: 60, 2: 22}".to_string()); + assert_eq!(cache.to_string(), "{3: 30, 6: 60, 2: 22}"); cache.set_capacity(2); - assert_eq!(cache.to_string(), "{3: 30, 6: 60}".to_string()); + assert_eq!(cache.to_string(), "{3: 30, 6: 60}"); } #[test] @@ -465,6 +465,6 @@ mod tests { cache.clear(); assert!(cache.get(&1).is_none()); assert!(cache.get(&2).is_none()); - assert_eq!(cache.to_string(), "{}".to_string()); + assert_eq!(cache.to_string(), "{}"); } } diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index c48f487c95cf7..078daf8fecae6 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -592,7 +592,7 @@ mod test { writer.write_line("testing").unwrap(); writer.write_str("testing").unwrap(); let mut r = BufReader::new(writer.get_ref()); - assert_eq!(r.read_to_string().unwrap(), "testingtesting\ntesting".to_string()); + assert_eq!(r.read_to_string().unwrap(), "testingtesting\ntesting"); } #[test] @@ -602,7 +602,7 @@ mod test { writer.write_char('\n').unwrap(); writer.write_char('ệ').unwrap(); let mut r = BufReader::new(writer.get_ref()); - assert_eq!(r.read_to_string().unwrap(), "a\nệ".to_string()); + assert_eq!(r.read_to_string().unwrap(), "a\nệ"); } #[test] diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 5a56636ffa41c..a9e653e267a80 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -2005,14 +2005,14 @@ mod tests { fn test_show() { use super::*; - assert_eq!(format!("{}", USER_READ), "0400".to_string()); - assert_eq!(format!("{}", USER_FILE), "0644".to_string()); - assert_eq!(format!("{}", USER_EXEC), "0755".to_string()); - assert_eq!(format!("{}", USER_RWX), "0700".to_string()); - assert_eq!(format!("{}", GROUP_RWX), "0070".to_string()); - assert_eq!(format!("{}", OTHER_RWX), "0007".to_string()); - assert_eq!(format!("{}", ALL_PERMISSIONS), "0777".to_string()); - assert_eq!(format!("{}", USER_READ | USER_WRITE | OTHER_WRITE), "0602".to_string()); + assert_eq!(format!("{}", USER_READ), "0400"); + assert_eq!(format!("{}", USER_FILE), "0644"); + assert_eq!(format!("{}", USER_EXEC), "0755"); + assert_eq!(format!("{}", USER_RWX), "0700"); + assert_eq!(format!("{}", GROUP_RWX), "0070"); + assert_eq!(format!("{}", OTHER_RWX), "0007"); + assert_eq!(format!("{}", ALL_PERMISSIONS), "0777"); + assert_eq!(format!("{}", USER_READ | USER_WRITE | OTHER_WRITE), "0602"); } fn _ensure_buffer_is_object_safe(x: &T) -> &Buffer { diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 4812e911cc481..20e2753392c1b 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -640,10 +640,10 @@ mod test { #[test] fn ipv6_addr_to_string() { let a1 = Ipv6Addr(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x280); - assert!(a1.to_string() == "::ffff:192.0.2.128".to_string() || - a1.to_string() == "::FFFF:192.0.2.128".to_string()); + assert!(a1.to_string() == "::ffff:192.0.2.128" || + a1.to_string() == "::FFFF:192.0.2.128"); assert_eq!(Ipv6Addr(8, 9, 10, 11, 12, 13, 14, 15).to_string(), - "8:9:a:b:c:d:e:f".to_string()); + "8:9:a:b:c:d:e:f"); } #[test] diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 53c672b4302d4..a4ca77e92fa08 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -810,7 +810,7 @@ mod tests { fn stdout_works() { let mut cmd = Command::new("echo"); cmd.arg("foobar").stdout(CreatePipe(false, true)); - assert_eq!(run_output(cmd), "foobar\n".to_string()); + assert_eq!(run_output(cmd), "foobar\n"); } #[cfg(all(unix, not(target_os="android")))] @@ -820,7 +820,7 @@ mod tests { cmd.arg("-c").arg("pwd") .cwd(&Path::new("/")) .stdout(CreatePipe(false, true)); - assert_eq!(run_output(cmd), "/\n".to_string()); + assert_eq!(run_output(cmd), "/\n"); } #[cfg(all(unix, not(target_os="android")))] @@ -835,7 +835,7 @@ mod tests { drop(p.stdin.take()); let out = read_all(p.stdout.as_mut().unwrap() as &mut Reader); assert!(p.wait().unwrap().success()); - assert_eq!(out, "foobar\n".to_string()); + assert_eq!(out, "foobar\n"); } #[cfg(not(target_os="android"))] @@ -900,7 +900,7 @@ mod tests { let output_str = str::from_utf8(output.as_slice()).unwrap(); assert!(status.success()); - assert_eq!(output_str.trim().to_string(), "hello".to_string()); + assert_eq!(output_str.trim().to_string(), "hello"); // FIXME #7224 if !running_on_valgrind() { assert_eq!(error, Vec::new()); @@ -941,7 +941,7 @@ mod tests { let output_str = str::from_utf8(output.as_slice()).unwrap(); assert!(status.success()); - assert_eq!(output_str.trim().to_string(), "hello".to_string()); + assert_eq!(output_str.trim().to_string(), "hello"); // FIXME #7224 if !running_on_valgrind() { assert_eq!(error, Vec::new()); diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 89d5b7a8acd92..fce1ee7e9b457 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -527,7 +527,7 @@ mod tests { set_stdout(box w); println!("hello!"); }); - assert_eq!(r.read_to_string().unwrap(), "hello!\n".to_string()); + assert_eq!(r.read_to_string().unwrap(), "hello!\n"); } #[test] diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index b42286c0308ce..c87f40f351bc0 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -428,28 +428,28 @@ mod tests { #[test] fn test_int_to_str_overflow() { let mut i8_val: i8 = 127_i8; - assert_eq!(i8_val.to_string(), "127".to_string()); + assert_eq!(i8_val.to_string(), "127"); i8_val += 1 as i8; - assert_eq!(i8_val.to_string(), "-128".to_string()); + assert_eq!(i8_val.to_string(), "-128"); let mut i16_val: i16 = 32_767_i16; - assert_eq!(i16_val.to_string(), "32767".to_string()); + assert_eq!(i16_val.to_string(), "32767"); i16_val += 1 as i16; - assert_eq!(i16_val.to_string(), "-32768".to_string()); + assert_eq!(i16_val.to_string(), "-32768"); let mut i32_val: i32 = 2_147_483_647_i32; - assert_eq!(i32_val.to_string(), "2147483647".to_string()); + assert_eq!(i32_val.to_string(), "2147483647"); i32_val += 1 as i32; - assert_eq!(i32_val.to_string(), "-2147483648".to_string()); + assert_eq!(i32_val.to_string(), "-2147483648"); let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; - assert_eq!(i64_val.to_string(), "9223372036854775807".to_string()); + assert_eq!(i64_val.to_string(), "9223372036854775807"); i64_val += 1 as i64; - assert_eq!(i64_val.to_string(), "-9223372036854775808".to_string()); + assert_eq!(i64_val.to_string(), "-9223372036854775808"); } } diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 7b79e53520140..0baefb11cf8f2 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -79,28 +79,28 @@ mod tests { #[test] fn test_uint_to_str_overflow() { let mut u8_val: u8 = 255_u8; - assert_eq!(u8_val.to_string(), "255".to_string()); + assert_eq!(u8_val.to_string(), "255"); u8_val += 1 as u8; - assert_eq!(u8_val.to_string(), "0".to_string()); + assert_eq!(u8_val.to_string(), "0"); let mut u16_val: u16 = 65_535_u16; - assert_eq!(u16_val.to_string(), "65535".to_string()); + assert_eq!(u16_val.to_string(), "65535"); u16_val += 1 as u16; - assert_eq!(u16_val.to_string(), "0".to_string()); + assert_eq!(u16_val.to_string(), "0"); let mut u32_val: u32 = 4_294_967_295_u32; - assert_eq!(u32_val.to_string(), "4294967295".to_string()); + assert_eq!(u32_val.to_string(), "4294967295"); u32_val += 1 as u32; - assert_eq!(u32_val.to_string(), "0".to_string()); + assert_eq!(u32_val.to_string(), "0"); let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; - assert_eq!(u64_val.to_string(), "18446744073709551615".to_string()); + assert_eq!(u64_val.to_string(), "18446744073709551615"); u64_val += 1 as u64; - assert_eq!(u64_val.to_string(), "0".to_string()); + assert_eq!(u64_val.to_string(), "0"); } #[test] diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 366e3125c6587..512756ececda4 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1321,9 +1321,9 @@ mod tests { #[test] fn test_display_str() { let path = Path::new("foo"); - assert_eq!(path.display().to_string(), "foo".to_string()); + assert_eq!(path.display().to_string(), "foo"); let path = Path::new(b"\\"); - assert_eq!(path.filename_display().to_string(), "".to_string()); + assert_eq!(path.filename_display().to_string(), ""); let path = Path::new("foo"); let mo = path.display().as_cow(); diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 159fc3080e836..93690323d3125 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -1012,7 +1012,7 @@ mod test { macro_rules! t( ($a:expr, $b:expr) => ({ let mut m = Vec::new(); super::demangle(&mut m, $a).unwrap(); - assert_eq!(String::from_utf8(m).unwrap(), $b.to_string()); + assert_eq!(String::from_utf8(m).unwrap(), $b); }) ) #[test] diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index 79e0d487cadb9..a8c9983e5aac5 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -153,7 +153,7 @@ mod test { #[test] fn test_from_value() { let mut f = Future::from_value("snail".to_string()); - assert_eq!(f.get(), "snail".to_string()); + assert_eq!(f.get(), "snail"); } #[test] @@ -161,25 +161,25 @@ mod test { let (tx, rx) = channel(); tx.send("whale".to_string()); let mut f = Future::from_receiver(rx); - assert_eq!(f.get(), "whale".to_string()); + assert_eq!(f.get(), "whale"); } #[test] fn test_from_fn() { let mut f = Future::from_fn(proc() "brail".to_string()); - assert_eq!(f.get(), "brail".to_string()); + assert_eq!(f.get(), "brail"); } #[test] fn test_interface_get() { let mut f = Future::from_value("fail".to_string()); - assert_eq!(f.get(), "fail".to_string()); + assert_eq!(f.get(), "fail"); } #[test] fn test_interface_unwrap() { let f = Future::from_value("fail".to_string()); - assert_eq!(f.unwrap(), "fail".to_string()); + assert_eq!(f.unwrap(), "fail"); } #[test] @@ -191,7 +191,7 @@ mod test { #[test] fn test_spawn() { let mut f = Future::spawn(proc() "bale".to_string()); - assert_eq!(f.get(), "bale".to_string()); + assert_eq!(f.get(), "bale"); } #[test] diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 2af5e4890e849..02548bedf028b 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -484,24 +484,24 @@ mod tests { assert_eq!( test_wrapper("prog", &["aaa", "bbb", "ccc"]), - "prog aaa bbb ccc".to_string() + "prog aaa bbb ccc" ); assert_eq!( test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa"]), - "\"C:\\Program Files\\blah\\blah.exe\" aaa".to_string() + "\"C:\\Program Files\\blah\\blah.exe\" aaa" ); assert_eq!( test_wrapper("C:\\Program Files\\test", &["aa\"bb"]), - "\"C:\\Program Files\\test\" aa\\\"bb".to_string() + "\"C:\\Program Files\\test\" aa\\\"bb" ); assert_eq!( test_wrapper("echo", &["a b c"]), - "echo \"a b c\"".to_string() + "echo \"a b c\"" ); assert_eq!( test_wrapper("\u03c0\u042f\u97f3\u00e6\u221e", &[]), - "\u03c0\u042f\u97f3\u00e6\u221e".to_string() + "\u03c0\u042f\u97f3\u00e6\u221e" ); } } diff --git a/src/libstd/task.rs b/src/libstd/task.rs index c433dfa08f4f6..0fb9e5b5c4376 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -287,21 +287,21 @@ mod test { #[test] fn test_owned_named_task() { TaskBuilder::new().named("ada lovelace".to_string()).try(proc() { - assert!(name().unwrap() == "ada lovelace".to_string()); + assert!(name().unwrap() == "ada lovelace"); }).map_err(|_| ()).unwrap(); } #[test] fn test_static_named_task() { TaskBuilder::new().named("ada lovelace").try(proc() { - assert!(name().unwrap() == "ada lovelace".to_string()); + assert!(name().unwrap() == "ada lovelace"); }).map_err(|_| ()).unwrap(); } #[test] fn test_send_named_task() { TaskBuilder::new().named("ada lovelace".into_cow()).try(proc() { - assert!(name().unwrap() == "ada lovelace".to_string()); + assert!(name().unwrap() == "ada lovelace"); }).map_err(|_| ()).unwrap(); } @@ -462,7 +462,7 @@ mod test { Err(e) => { type T = String; assert!(e.is::()); - assert_eq!(*e.downcast::().unwrap(), "owned string".to_string()); + assert_eq!(*e.downcast::().unwrap(), "owned string"); } Ok(()) => panic!() } @@ -509,7 +509,7 @@ mod test { assert!(r.is_ok()); let output = reader.read_to_string().unwrap(); - assert_eq!(output, "Hello, world!".to_string()); + assert_eq!(output, "Hello, world!"); } // NOTE: the corresponding test for stderr is in run-pass/task-stderr, due diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index ec2d62ff85cb1..1c36024bd9678 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -538,20 +538,20 @@ mod tests { #[test] fn test_duration_fmt() { - assert_eq!(Duration::zero().to_string(), "PT0S".to_string()); - assert_eq!(Duration::days(42).to_string(), "P42D".to_string()); - assert_eq!(Duration::days(-42).to_string(), "-P42D".to_string()); - assert_eq!(Duration::seconds(42).to_string(), "PT42S".to_string()); - assert_eq!(Duration::milliseconds(42).to_string(), "PT0.042S".to_string()); - assert_eq!(Duration::microseconds(42).to_string(), "PT0.000042S".to_string()); - assert_eq!(Duration::nanoseconds(42).to_string(), "PT0.000000042S".to_string()); + assert_eq!(Duration::zero().to_string(), "PT0S"); + assert_eq!(Duration::days(42).to_string(), "P42D"); + assert_eq!(Duration::days(-42).to_string(), "-P42D"); + assert_eq!(Duration::seconds(42).to_string(), "PT42S"); + assert_eq!(Duration::milliseconds(42).to_string(), "PT0.042S"); + assert_eq!(Duration::microseconds(42).to_string(), "PT0.000042S"); + assert_eq!(Duration::nanoseconds(42).to_string(), "PT0.000000042S"); assert_eq!((Duration::days(7) + Duration::milliseconds(6543)).to_string(), - "P7DT6.543S".to_string()); - assert_eq!(Duration::seconds(-86401).to_string(), "-P1DT1S".to_string()); - assert_eq!(Duration::nanoseconds(-1).to_string(), "-PT0.000000001S".to_string()); + "P7DT6.543S"); + assert_eq!(Duration::seconds(-86401).to_string(), "-P1DT1S"); + assert_eq!(Duration::nanoseconds(-1).to_string(), "-PT0.000000001S"); // the format specifier should have no effect on `Duration` assert_eq!(format!("{:30}", Duration::days(1) + Duration::milliseconds(2345)), - "P1DT2.345S".to_string()); + "P1DT2.345S"); } } From 93e99b55f8ed8d9c601c4ac176ac06dc88953543 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 19:52:53 -0500 Subject: [PATCH 31/35] libsyntax: remove unnecessary `to_string()` calls --- src/libsyntax/codemap.rs | 12 ++++++------ src/libsyntax/parse/lexer/comments.rs | 22 +++++++++++----------- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/print/pprust.rs | 6 +++--- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 7df09260cfc2f..6bcf562204bed 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -614,11 +614,11 @@ mod test { let cm = init_code_map(); let fmabp1 = cm.lookup_byte_offset(BytePos(22)); - assert_eq!(fmabp1.fm.name, "blork.rs".to_string()); + assert_eq!(fmabp1.fm.name, "blork.rs"); assert_eq!(fmabp1.pos, BytePos(22)); let fmabp2 = cm.lookup_byte_offset(BytePos(24)); - assert_eq!(fmabp2.fm.name, "blork2.rs".to_string()); + assert_eq!(fmabp2.fm.name, "blork2.rs"); assert_eq!(fmabp2.pos, BytePos(0)); } @@ -640,12 +640,12 @@ mod test { let cm = init_code_map(); let loc1 = cm.lookup_char_pos(BytePos(22)); - assert_eq!(loc1.file.name, "blork.rs".to_string()); + assert_eq!(loc1.file.name, "blork.rs"); assert_eq!(loc1.line, 2); assert_eq!(loc1.col, CharPos(10)); let loc2 = cm.lookup_char_pos(BytePos(24)); - assert_eq!(loc2.file.name, "blork2.rs".to_string()); + assert_eq!(loc2.file.name, "blork2.rs"); assert_eq!(loc2.line, 1); assert_eq!(loc2.col, CharPos(0)); } @@ -701,7 +701,7 @@ mod test { let span = Span {lo: BytePos(12), hi: BytePos(23), expn_id: NO_EXPANSION}; let file_lines = cm.span_to_lines(span); - assert_eq!(file_lines.file.name, "blork.rs".to_string()); + assert_eq!(file_lines.file.name, "blork.rs"); assert_eq!(file_lines.lines.len(), 1); assert_eq!(file_lines.lines[0], 1u); } @@ -723,6 +723,6 @@ mod test { let span = Span {lo: BytePos(12), hi: BytePos(23), expn_id: NO_EXPANSION}; let sstr = cm.span_to_string(span); - assert_eq!(sstr, "blork.rs:2:1: 2:12".to_string()); + assert_eq!(sstr, "blork.rs:2:1: 2:12"); } } diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index f9877d937ca16..aeec6ee13fd41 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -389,41 +389,41 @@ mod test { #[test] fn test_block_doc_comment_1() { let comment = "/**\n * Test \n ** Test\n * Test\n*/"; let stripped = strip_doc_comment_decoration(comment); - assert_eq!(stripped, " Test \n* Test\n Test".to_string()); + assert_eq!(stripped, " Test \n* Test\n Test"); } #[test] fn test_block_doc_comment_2() { let comment = "/**\n * Test\n * Test\n*/"; let stripped = strip_doc_comment_decoration(comment); - assert_eq!(stripped, " Test\n Test".to_string()); + assert_eq!(stripped, " Test\n Test"); } #[test] fn test_block_doc_comment_3() { let comment = "/**\n let a: *int;\n *a = 5;\n*/"; let stripped = strip_doc_comment_decoration(comment); - assert_eq!(stripped, " let a: *int;\n *a = 5;".to_string()); + assert_eq!(stripped, " let a: *int;\n *a = 5;"); } #[test] fn test_block_doc_comment_4() { let comment = "/*******************\n test\n *********************/"; let stripped = strip_doc_comment_decoration(comment); - assert_eq!(stripped, " test".to_string()); + assert_eq!(stripped, " test"); } #[test] fn test_line_doc_comment() { let stripped = strip_doc_comment_decoration("/// test"); - assert_eq!(stripped, " test".to_string()); + assert_eq!(stripped, " test"); let stripped = strip_doc_comment_decoration("///! test"); - assert_eq!(stripped, " test".to_string()); + assert_eq!(stripped, " test"); let stripped = strip_doc_comment_decoration("// test"); - assert_eq!(stripped, " test".to_string()); + assert_eq!(stripped, " test"); let stripped = strip_doc_comment_decoration("// test"); - assert_eq!(stripped, " test".to_string()); + assert_eq!(stripped, " test"); let stripped = strip_doc_comment_decoration("///test"); - assert_eq!(stripped, "test".to_string()); + assert_eq!(stripped, "test"); let stripped = strip_doc_comment_decoration("///!test"); - assert_eq!(stripped, "test".to_string()); + assert_eq!(stripped, "test"); let stripped = strip_doc_comment_decoration("//test"); - assert_eq!(stripped, "test".to_string()); + assert_eq!(stripped, "test"); } } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 8d0c2de048a56..951fe11a470bb 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -954,7 +954,7 @@ mod test { }\ ]\ }\ -]".to_string() +]" ); } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 40303cdffe3f1..6ce0ee79c6230 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2961,9 +2961,9 @@ mod test { variadic: false }; let generics = ast_util::empty_generics(); - assert_eq!(&fun_to_string(&decl, ast::NormalFn, abba_ident, + assert_eq!(fun_to_string(&decl, ast::NormalFn, abba_ident, None, &generics), - &"fn abba()".to_string()); + "fn abba()"); } #[test] @@ -2981,7 +2981,7 @@ mod test { }); let varstr = variant_to_string(&var); - assert_eq!(&varstr,&"pub principal_skinner".to_string()); + assert_eq!(varstr, "pub principal_skinner"); } #[test] From 00c778669024f06969f7d97b1f340c5d0c4bc326 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 19:53:58 -0500 Subject: [PATCH 32/35] libterm: remove unnecessary `to_string()` calls --- src/libterm/terminfo/searcher.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libterm/terminfo/searcher.rs b/src/libterm/terminfo/searcher.rs index 2c1d76c7a405e..33bfd69f71bb8 100644 --- a/src/libterm/terminfo/searcher.rs +++ b/src/libterm/terminfo/searcher.rs @@ -102,10 +102,10 @@ fn test_get_dbpath_for_term() { let p = get_dbpath_for_term(t).expect("no terminfo entry found"); p.as_str().unwrap().to_string() }; - assert!(x("screen") == "/usr/share/terminfo/s/screen".to_string()); + assert!(x("screen") == "/usr/share/terminfo/s/screen"); assert!(get_dbpath_for_term("") == None); setenv("TERMINFO_DIRS", ":"); - assert!(x("screen") == "/usr/share/terminfo/s/screen".to_string()); + assert!(x("screen") == "/usr/share/terminfo/s/screen"); unsetenv("TERMINFO_DIRS"); } From 66f52f4c9b7b3f43f08a163d886cd10d34bc356b Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 19:55:37 -0500 Subject: [PATCH 33/35] libtest: remove unnecessary `to_string()` calls --- src/libtest/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 6e202983ad8cc..f445e812d2c19 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1560,7 +1560,7 @@ mod tests { assert_eq!(filtered.len(), 1); assert_eq!(filtered[0].desc.name.to_string(), - "1".to_string()); + "1"); assert!(filtered[0].desc.ignore == false); } From 2ed42bfbd161044b381f0ca2aedcfd0dd29a5263 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 19:58:14 -0500 Subject: [PATCH 34/35] libtime: remove unnecessary `to_string()` calls --- src/libtime/lib.rs | 116 ++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/src/libtime/lib.rs b/src/libtime/lib.rs index a77a6276a8b4e..a0749407b26ff 100644 --- a/src/libtime/lib.rs +++ b/src/libtime/lib.rs @@ -1564,8 +1564,8 @@ mod tests { debug!("test_ctime: {} {}", utc.asctime(), local.asctime()); - assert_eq!(utc.asctime().to_string(), "Fri Feb 13 23:31:30 2009".to_string()); - assert_eq!(local.asctime().to_string(), "Fri Feb 13 15:31:30 2009".to_string()); + assert_eq!(utc.asctime().to_string(), "Fri Feb 13 23:31:30 2009"); + assert_eq!(local.asctime().to_string(), "Fri Feb 13 15:31:30 2009"); } fn test_ctime() { @@ -1577,8 +1577,8 @@ mod tests { debug!("test_ctime: {} {}", utc.ctime(), local.ctime()); - assert_eq!(utc.ctime().to_string(), "Fri Feb 13 15:31:30 2009".to_string()); - assert_eq!(local.ctime().to_string(), "Fri Feb 13 15:31:30 2009".to_string()); + assert_eq!(utc.ctime().to_string(), "Fri Feb 13 15:31:30 2009"); + assert_eq!(local.ctime().to_string(), "Fri Feb 13 15:31:30 2009"); } fn test_strftime() { @@ -1588,56 +1588,56 @@ mod tests { let utc = at_utc(time); let local = at(time); - assert_eq!(local.strftime("").unwrap().to_string(), "".to_string()); - assert_eq!(local.strftime("%A").unwrap().to_string(), "Friday".to_string()); - assert_eq!(local.strftime("%a").unwrap().to_string(), "Fri".to_string()); - assert_eq!(local.strftime("%B").unwrap().to_string(), "February".to_string()); - assert_eq!(local.strftime("%b").unwrap().to_string(), "Feb".to_string()); - assert_eq!(local.strftime("%C").unwrap().to_string(), "20".to_string()); + assert_eq!(local.strftime("").unwrap().to_string(), ""); + assert_eq!(local.strftime("%A").unwrap().to_string(), "Friday"); + assert_eq!(local.strftime("%a").unwrap().to_string(), "Fri"); + assert_eq!(local.strftime("%B").unwrap().to_string(), "February"); + assert_eq!(local.strftime("%b").unwrap().to_string(), "Feb"); + assert_eq!(local.strftime("%C").unwrap().to_string(), "20"); assert_eq!(local.strftime("%c").unwrap().to_string(), - "Fri Feb 13 15:31:30 2009".to_string()); - assert_eq!(local.strftime("%D").unwrap().to_string(), "02/13/09".to_string()); - assert_eq!(local.strftime("%d").unwrap().to_string(), "13".to_string()); - assert_eq!(local.strftime("%e").unwrap().to_string(), "13".to_string()); - assert_eq!(local.strftime("%F").unwrap().to_string(), "2009-02-13".to_string()); - assert_eq!(local.strftime("%f").unwrap().to_string(), "000054321".to_string()); - assert_eq!(local.strftime("%G").unwrap().to_string(), "2009".to_string()); - assert_eq!(local.strftime("%g").unwrap().to_string(), "09".to_string()); - assert_eq!(local.strftime("%H").unwrap().to_string(), "15".to_string()); - assert_eq!(local.strftime("%h").unwrap().to_string(), "Feb".to_string()); - assert_eq!(local.strftime("%I").unwrap().to_string(), "03".to_string()); - assert_eq!(local.strftime("%j").unwrap().to_string(), "044".to_string()); - assert_eq!(local.strftime("%k").unwrap().to_string(), "15".to_string()); - assert_eq!(local.strftime("%l").unwrap().to_string(), " 3".to_string()); - assert_eq!(local.strftime("%M").unwrap().to_string(), "31".to_string()); - assert_eq!(local.strftime("%m").unwrap().to_string(), "02".to_string()); - assert_eq!(local.strftime("%n").unwrap().to_string(), "\n".to_string()); - assert_eq!(local.strftime("%P").unwrap().to_string(), "pm".to_string()); - assert_eq!(local.strftime("%p").unwrap().to_string(), "PM".to_string()); - assert_eq!(local.strftime("%R").unwrap().to_string(), "15:31".to_string()); - assert_eq!(local.strftime("%r").unwrap().to_string(), "03:31:30 PM".to_string()); - assert_eq!(local.strftime("%S").unwrap().to_string(), "30".to_string()); - assert_eq!(local.strftime("%s").unwrap().to_string(), "1234567890".to_string()); - assert_eq!(local.strftime("%T").unwrap().to_string(), "15:31:30".to_string()); - assert_eq!(local.strftime("%t").unwrap().to_string(), "\t".to_string()); - assert_eq!(local.strftime("%U").unwrap().to_string(), "06".to_string()); - assert_eq!(local.strftime("%u").unwrap().to_string(), "5".to_string()); - assert_eq!(local.strftime("%V").unwrap().to_string(), "07".to_string()); - assert_eq!(local.strftime("%v").unwrap().to_string(), "13-Feb-2009".to_string()); - assert_eq!(local.strftime("%W").unwrap().to_string(), "06".to_string()); - assert_eq!(local.strftime("%w").unwrap().to_string(), "5".to_string()); + "Fri Feb 13 15:31:30 2009"); + assert_eq!(local.strftime("%D").unwrap().to_string(), "02/13/09"); + assert_eq!(local.strftime("%d").unwrap().to_string(), "13"); + assert_eq!(local.strftime("%e").unwrap().to_string(), "13"); + assert_eq!(local.strftime("%F").unwrap().to_string(), "2009-02-13"); + assert_eq!(local.strftime("%f").unwrap().to_string(), "000054321"); + assert_eq!(local.strftime("%G").unwrap().to_string(), "2009"); + assert_eq!(local.strftime("%g").unwrap().to_string(), "09"); + assert_eq!(local.strftime("%H").unwrap().to_string(), "15"); + assert_eq!(local.strftime("%h").unwrap().to_string(), "Feb"); + assert_eq!(local.strftime("%I").unwrap().to_string(), "03"); + assert_eq!(local.strftime("%j").unwrap().to_string(), "044"); + assert_eq!(local.strftime("%k").unwrap().to_string(), "15"); + assert_eq!(local.strftime("%l").unwrap().to_string(), " 3"); + assert_eq!(local.strftime("%M").unwrap().to_string(), "31"); + assert_eq!(local.strftime("%m").unwrap().to_string(), "02"); + assert_eq!(local.strftime("%n").unwrap().to_string(), "\n"); + assert_eq!(local.strftime("%P").unwrap().to_string(), "pm"); + assert_eq!(local.strftime("%p").unwrap().to_string(), "PM"); + assert_eq!(local.strftime("%R").unwrap().to_string(), "15:31"); + assert_eq!(local.strftime("%r").unwrap().to_string(), "03:31:30 PM"); + assert_eq!(local.strftime("%S").unwrap().to_string(), "30"); + assert_eq!(local.strftime("%s").unwrap().to_string(), "1234567890"); + assert_eq!(local.strftime("%T").unwrap().to_string(), "15:31:30"); + assert_eq!(local.strftime("%t").unwrap().to_string(), "\t"); + assert_eq!(local.strftime("%U").unwrap().to_string(), "06"); + assert_eq!(local.strftime("%u").unwrap().to_string(), "5"); + assert_eq!(local.strftime("%V").unwrap().to_string(), "07"); + assert_eq!(local.strftime("%v").unwrap().to_string(), "13-Feb-2009"); + assert_eq!(local.strftime("%W").unwrap().to_string(), "06"); + assert_eq!(local.strftime("%w").unwrap().to_string(), "5"); // FIXME (#2350): support locale - assert_eq!(local.strftime("%X").unwrap().to_string(), "15:31:30".to_string()); + assert_eq!(local.strftime("%X").unwrap().to_string(), "15:31:30"); // FIXME (#2350): support locale - assert_eq!(local.strftime("%x").unwrap().to_string(), "02/13/09".to_string()); - assert_eq!(local.strftime("%Y").unwrap().to_string(), "2009".to_string()); - assert_eq!(local.strftime("%y").unwrap().to_string(), "09".to_string()); + assert_eq!(local.strftime("%x").unwrap().to_string(), "02/13/09"); + assert_eq!(local.strftime("%Y").unwrap().to_string(), "2009"); + assert_eq!(local.strftime("%y").unwrap().to_string(), "09"); // FIXME (#2350): support locale - assert_eq!(local.strftime("%Z").unwrap().to_string(), "".to_string()); - assert_eq!(local.strftime("%z").unwrap().to_string(), "-0800".to_string()); + assert_eq!(local.strftime("%Z").unwrap().to_string(), ""); + assert_eq!(local.strftime("%z").unwrap().to_string(), "-0800"); assert_eq!(local.strftime("%+").unwrap().to_string(), - "2009-02-13T15:31:30-08:00".to_string()); - assert_eq!(local.strftime("%%").unwrap().to_string(), "%".to_string()); + "2009-02-13T15:31:30-08:00"); + assert_eq!(local.strftime("%%").unwrap().to_string(), "%"); let invalid_specifiers = ["%E", "%J", "%K", "%L", "%N", "%O", "%o", "%Q", "%q"]; for &sp in invalid_specifiers.iter() { @@ -1646,16 +1646,16 @@ mod tests { assert_eq!(local.strftime("%").unwrap_err(), MissingFormatConverter); assert_eq!(local.strftime("%A %").unwrap_err(), MissingFormatConverter); - assert_eq!(local.asctime().to_string(), "Fri Feb 13 15:31:30 2009".to_string()); - assert_eq!(local.ctime().to_string(), "Fri Feb 13 15:31:30 2009".to_string()); - assert_eq!(local.rfc822z().to_string(), "Fri, 13 Feb 2009 15:31:30 -0800".to_string()); - assert_eq!(local.rfc3339().to_string(), "2009-02-13T15:31:30-08:00".to_string()); + assert_eq!(local.asctime().to_string(), "Fri Feb 13 15:31:30 2009"); + assert_eq!(local.ctime().to_string(), "Fri Feb 13 15:31:30 2009"); + assert_eq!(local.rfc822z().to_string(), "Fri, 13 Feb 2009 15:31:30 -0800"); + assert_eq!(local.rfc3339().to_string(), "2009-02-13T15:31:30-08:00"); - assert_eq!(utc.asctime().to_string(), "Fri Feb 13 23:31:30 2009".to_string()); - assert_eq!(utc.ctime().to_string(), "Fri Feb 13 15:31:30 2009".to_string()); - assert_eq!(utc.rfc822().to_string(), "Fri, 13 Feb 2009 23:31:30 GMT".to_string()); - assert_eq!(utc.rfc822z().to_string(), "Fri, 13 Feb 2009 23:31:30 -0000".to_string()); - assert_eq!(utc.rfc3339().to_string(), "2009-02-13T23:31:30Z".to_string()); + assert_eq!(utc.asctime().to_string(), "Fri Feb 13 23:31:30 2009"); + assert_eq!(utc.ctime().to_string(), "Fri Feb 13 15:31:30 2009"); + assert_eq!(utc.rfc822().to_string(), "Fri, 13 Feb 2009 23:31:30 GMT"); + assert_eq!(utc.rfc822z().to_string(), "Fri, 13 Feb 2009 23:31:30 -0000"); + assert_eq!(utc.rfc3339().to_string(), "2009-02-13T23:31:30Z"); } fn test_timespec_eq_ord() { From 1fea900de7f11d665086141806246842c03b9fc5 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 7 Dec 2014 08:49:17 -0500 Subject: [PATCH 35/35] Fix syntax error on android tests --- src/libstd/io/process.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index a4ca77e92fa08..61ebfb06c71fe 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -1049,10 +1049,10 @@ mod tests { for &(ref k, ref v) in r.iter() { // don't check android RANDOM variables if *k != "RANDOM".to_string() { - assert!(output..contains(format!("{}={}", + assert!(output.contains(format!("{}={}", *k, *v).as_slice()) || - output..contains(format!("{}=\'{}\'", + output.contains(format!("{}=\'{}\'", *k, *v).as_slice())); }