diff options
| author | bors <bors@rust-lang.org> | 2014-12-08 02:32:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-12-08 02:32:31 +0000 |
| commit | 83a44c7fa676b4e5e546ce3d4624e585f9a1e899 (patch) | |
| tree | 36d7db1d2567d86816d4ac6a1ec86276974dbc65 /src/libcollections | |
| parent | 8bca470c5acf13aa20022a2c462a89f72de721fc (diff) | |
| parent | 1fea900de7f11d665086141806246842c03b9fc5 (diff) | |
| download | rust-83a44c7fa676b4e5e546ce3d4624e585f9a1e899.tar.gz rust-83a44c7fa676b4e5e546ce3d4624e585f9a1e899.zip | |
auto merge of #19378 : japaric/rust/no-as-slice, r=alexcrichton
Now that we have an overloaded comparison (`==`) operator, and that `Vec`/`String` deref to `[T]`/`str` on method calls, many `as_slice()`/`as_mut_slice()`/`to_string()` calls have become redundant. This patch removes them. These were the most common patterns: - `assert_eq(test_output.as_slice(), "ground truth")` -> `assert_eq(test_output, "ground truth")` - `assert_eq(test_output, "ground truth".to_string())` -> `assert_eq(test_output, "ground truth")` - `vec.as_mut_slice().sort()` -> `vec.sort()` - `vec.as_slice().slice(from, to)` -> `vec.slice(from_to)` --- Note that e.g. `a_string.push_str(b_string.as_slice())` has been left untouched in this PR, since we first need to settle down whether we want to favor the `&*b_string` or the `b_string[]` notation. This is rebased on top of #19167 cc @alexcrichton @aturon
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/binary_heap.rs | 8 | ||||
| -rw-r--r-- | src/libcollections/bit.rs | 20 | ||||
| -rw-r--r-- | src/libcollections/btree/node.rs | 30 | ||||
| -rw-r--r-- | src/libcollections/btree/set.rs | 4 | ||||
| -rw-r--r-- | src/libcollections/dlist.rs | 8 | ||||
| -rw-r--r-- | src/libcollections/enum_set.rs | 6 | ||||
| -rw-r--r-- | src/libcollections/ring_buf.rs | 12 | ||||
| -rw-r--r-- | src/libcollections/slice.rs | 110 | ||||
| -rw-r--r-- | src/libcollections/str.rs | 67 | ||||
| -rw-r--r-- | src/libcollections/string.rs | 70 | ||||
| -rw-r--r-- | src/libcollections/tree/map.rs | 4 | ||||
| -rw-r--r-- | src/libcollections/tree/set.rs | 4 | ||||
| -rw-r--r-- | src/libcollections/trie/map.rs | 4 | ||||
| -rw-r--r-- | src/libcollections/trie/set.rs | 4 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 29 | ||||
| -rw-r--r-- | src/libcollections/vec_map.rs | 3 |
16 files changed, 190 insertions, 193 deletions
diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 330b9392974..e321ef16f66 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -485,7 +485,7 @@ impl<T: Ord> BinaryHeap<T> { 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() @@ -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<uint> = xs.as_slice().iter().rev().map(|&x| x).collect(); + let mut q: BinaryHeap<uint> = 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 903a9bd9823..ad5732c47a8 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::<Vec<uint>>(); - 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::<Vec<uint>>(); - 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::<Vec<uint>>(); - 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::<Vec<uint>>(); - assert_eq!(actual.as_slice(), expected.as_slice()); + assert_eq!(actual, expected); } #[test] @@ -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/node.rs b/src/libcollections/btree/node.rs index b40ff35cca1..3f53bad6518 100644 --- a/src/libcollections/btree/node.rs +++ b/src/libcollections/btree/node.rs @@ -158,43 +158,43 @@ impl <K, V> Node<K, V> { /// 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 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<K,V>> { - self.edges.as_slice().get(index) + self.edges.get(index) } /// Get the node's edge mutably at the given index pub fn edge_mut(&mut self, index: uint) -> Option<&mut Node<K,V>> { - 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<K,V> { - self.edges.as_mut_slice().unsafe_mut(index) + self.edges.unsafe_mut(index) } /// Pop an edge off the end of the node @@ -281,8 +281,8 @@ impl <K, V> Node<K, V> { 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,8 +292,8 @@ impl <K, V> Node<K, V> { 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()), - 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, @@ -477,8 +477,8 @@ fn split<T>(left: &mut Vec<T>) -> Vec<T> { 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 right_ptr = right.as_mut_slice().as_mut_ptr(); + let left_ptr = left.unsafe_get(left_len) as *const _; + 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/btree/set.rs b/src/libcollections/btree/set.rs index 3973b4774b3..573b5a9422b 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -646,7 +646,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/dlist.rs b/src/libcollections/dlist.rs index 39cdf0c4564..a30bb9e978b 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::<Vec<&int>>().as_slice()); + assert_eq!(a, n.iter().collect::<Vec<&int>>()); }); } @@ -1224,12 +1224,12 @@ mod tests { #[test] fn test_show() { let list: DList<int> = 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 2cbde0168a2..5e77cf66726 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 e11ba35367e..d9e5dde96ce 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::<Vec<&int>>().as_slice(), b); + assert_eq!(d.iter().collect::<Vec<&int>>(), 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::<Vec<&int>>().as_slice(), b); + assert_eq!(d.iter().collect::<Vec<&int>>(), 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::<Vec<&int>>().as_slice(), b); + assert_eq!(d.iter().rev().collect::<Vec<&int>>(), 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::<Vec<&int>>().as_slice(), b); + assert_eq!(d.iter().rev().collect::<Vec<&int>>(), b); } #[test] @@ -1495,12 +1495,12 @@ mod tests { #[test] fn test_show() { let ringbuf: RingBuf<int> = 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 6c13abdaf89..03b8ea8f20f 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<T: Clone> Iterator<Vec<T>> for Permutations<T> { 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<int> = 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<int> = 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::<Vec<uint>>(); 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])); } } @@ -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::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.split(|x| *x % 2 == 0).collect::<Vec<&[int]>>(), splits); let splits: &[&[int]] = &[&[], &[2,3,4,5]]; - assert_eq!(xs.split(|x| *x == 1).collect::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.split(|x| *x == 1).collect::<Vec<&[int]>>(), splits); let splits: &[&[int]] = &[&[1,2,3,4], &[]]; - assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>(), splits); let splits: &[&[int]] = &[&[1,2,3,4,5]]; - assert_eq!(xs.split(|x| *x == 10).collect::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.split(|x| *x == 10).collect::<Vec<&[int]>>(), splits); let splits: &[&[int]] = &[&[], &[], &[], &[], &[], &[]]; - assert_eq!(xs.split(|_| true).collect::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.split(|_| true).collect::<Vec<&[int]>>(), splits); let xs: &[int] = &[]; let splits: &[&[int]] = &[&[]]; - assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits); + assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>(), 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::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>(), splits); let splits: &[&[int]] = &[&[1], &[3,4,5]]; - assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>(), splits); let splits: &[&[int]] = &[&[], &[], &[], &[4,5]]; - assert_eq!(xs.splitn(3, |_| true).collect::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.splitn(3, |_| true).collect::<Vec<&[int]>>(), splits); let xs: &[int] = &[]; let splits: &[&[int]] = &[&[]]; - assert_eq!(xs.splitn(1, |x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits); + assert_eq!(xs.splitn(1, |x| *x == 5).collect::<Vec<&[int]>>(), 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::<Vec<&mut [int]>>().as_slice(), + assert_eq!(xs.splitn_mut(0, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>(), splits); let splits: &[&mut [int]] = &[&mut [1], &mut [3,4,5]]; - assert_eq!(xs.splitn_mut(1, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>().as_slice(), + assert_eq!(xs.splitn_mut(1, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>(), splits); let splits: &[&mut [int]] = &[&mut [], &mut [], &mut [], &mut [4,5]]; - assert_eq!(xs.splitn_mut(3, |_| true).collect::<Vec<&mut [int]>>().as_slice(), + assert_eq!(xs.splitn_mut(3, |_| true).collect::<Vec<&mut [int]>>(), splits); let xs: &mut [int] = &mut []; let splits: &[&mut [int]] = &[&mut []]; - assert_eq!(xs.splitn_mut(1, |x| *x == 5).collect::<Vec<&mut [int]>>().as_slice(), + assert_eq!(xs.splitn_mut(1, |x| *x == 5).collect::<Vec<&mut [int]>>(), 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::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::<Vec<&[int]>>(), splits); let splits: &[&[int]] = &[&[2,3,4,5], &[]]; - assert_eq!(xs.split(|x| *x == 1).rev().collect::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.split(|x| *x == 1).rev().collect::<Vec<&[int]>>(), splits); let splits: &[&[int]] = &[&[], &[1,2,3,4]]; - assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>(), splits); let splits: &[&[int]] = &[&[1,2,3,4,5]]; - assert_eq!(xs.split(|x| *x == 10).rev().collect::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.split(|x| *x == 10).rev().collect::<Vec<&[int]>>(), splits); let xs: &[int] = &[]; let splits: &[&[int]] = &[&[]]; - assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>().as_slice(), splits); + assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>(), 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::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.rsplitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>(), splits); let splits: &[&[int]] = &[&[5], &[1,2,3]]; - assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>(), splits); let splits: &[&[int]] = &[&[], &[], &[], &[1,2]]; - assert_eq!(xs.rsplitn(3, |_| true).collect::<Vec<&[int]>>().as_slice(), + assert_eq!(xs.rsplitn(3, |_| true).collect::<Vec<&[int]>>(), splits); let xs: &[int] = &[]; let splits: &[&[int]] = &[&[]]; - assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits); + assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::<Vec<&[int]>>(), 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::<Vec<&[int]>>().as_slice(), wins); + assert_eq!(v.windows(2).collect::<Vec<&[int]>>(), wins); let wins: &[&[int]] = &[&[1i,2,3], &[2,3,4]]; - assert_eq!(v.windows(3).collect::<Vec<&[int]>>().as_slice(), wins); + assert_eq!(v.windows(3).collect::<Vec<&[int]>>(), 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::<Vec<&[int]>>().as_slice(), chunks); + assert_eq!(v.chunks(2).collect::<Vec<&[int]>>(), chunks); let chunks: &[&[int]] = &[&[1i,2,3], &[4,5]]; - assert_eq!(v.chunks(3).collect::<Vec<&[int]>>().as_slice(), chunks); + assert_eq!(v.chunks(3).collect::<Vec<&[int]>>(), chunks); let chunks: &[&[int]] = &[&[1i,2,3,4,5]]; - assert_eq!(v.chunks(6).collect::<Vec<&[int]>>().as_slice(), chunks); + assert_eq!(v.chunks(6).collect::<Vec<&[int]>>(), chunks); let chunks: &[&[int]] = &[&[5i], &[3,4], &[1,2]]; - assert_eq!(v.chunks(2).rev().collect::<Vec<&[int]>>().as_slice(), chunks); + assert_eq!(v.chunks(2).rev().collect::<Vec<&[int]>>(), chunks); let mut it = v.chunks(2); assert_eq!(it.indexable(), 3); let chunk: &[int] = &[1,2]; @@ -1838,20 +1838,20 @@ mod tests { }) ) let empty: Vec<int> = 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] @@ -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 78cdda61104..28027198143 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -215,7 +215,7 @@ pub struct Decompositions<'a> { impl<'a> Iterator<char> for Decompositions<'a> { #[inline] fn next(&mut self) -> Option<char> { - match self.buffer.as_slice().head() { + match self.buffer.head() { Some(&(c, 0)) => { self.sorted = false; self.buffer.remove(0); @@ -915,10 +915,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); } @@ -926,7 +926,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] @@ -943,21 +943,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] @@ -989,7 +989,7 @@ mod tests { ($expected: expr, $string: expr) => { { let s = $string.concat(); - assert_eq!($expected, s.as_slice()); + assert_eq!($expected, s); } } } @@ -1027,7 +1027,7 @@ mod tests { ($expected: expr, $string: expr, $delim: expr) => { { let s = $string.connect($delim); - assert_eq!($expected, s.as_slice()); + assert_eq!($expected, s); } } } @@ -1148,7 +1148,7 @@ mod tests { let a = "ประเ"; let a2 = "دولة الكويتทศไทย中华"; - assert_eq!(data.replace(a, repl).as_slice(), a2); + assert_eq!(data.replace(a, repl), a2); } #[test] @@ -1158,7 +1158,7 @@ mod tests { let b = "ะเ"; let b2 = "ปรدولة الكويتทศไทย中华"; - assert_eq!(data.replace(b, repl).as_slice(), b2); + assert_eq!(data.replace(b, repl), b2); } #[test] @@ -1168,7 +1168,7 @@ mod tests { let c = "中华"; let c2 = "ประเทศไทยدولة الكويت"; - assert_eq!(data.replace(c, repl).as_slice(), c2); + assert_eq!(data.replace(c, repl), c2); } #[test] @@ -1177,7 +1177,7 @@ mod tests { let repl = "دولة الكويت"; let d = "ไท华"; - assert_eq!(data.replace(d, repl).as_slice(), data); + assert_eq!(data.replace(d, repl), data); } #[test] @@ -1213,7 +1213,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] @@ -1452,7 +1452,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] @@ -1487,7 +1487,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); @@ -1834,7 +1833,7 @@ mod tests { fn test_nfd_chars() { macro_rules! t { ($input: expr, $expected: expr) => { - assert_eq!($input.nfd_chars().collect::<String>(), $expected.into_string()); + assert_eq!($input.nfd_chars().collect::<String>(), $expected); } } t!("abc", "abc"); @@ -1853,7 +1852,7 @@ mod tests { fn test_nfkd_chars() { macro_rules! t { ($input: expr, $expected: expr) => { - assert_eq!($input.nfkd_chars().collect::<String>(), $expected.into_string()); + assert_eq!($input.nfkd_chars().collect::<String>(), $expected); } } t!("abc", "abc"); @@ -1872,7 +1871,7 @@ mod tests { fn test_nfc_chars() { macro_rules! t { ($input: expr, $expected: expr) => { - assert_eq!($input.nfc_chars().collect::<String>(), $expected.into_string()); + assert_eq!($input.nfc_chars().collect::<String>(), $expected); } } t!("abc", "abc"); @@ -1892,7 +1891,7 @@ mod tests { fn test_nfkc_chars() { macro_rules! t { ($input: expr, $expected: expr) => { - assert_eq!($input.nfkc_chars().collect::<String>(), $expected.into_string()); + assert_eq!($input.nfkc_chars().collect::<String>(), $expected); } } t!("abc", "abc"); @@ -2183,10 +2182,10 @@ mod tests { let s = "a̐éö̲\r\n"; let gr_inds = s.grapheme_indices(true).collect::<Vec<(uint, &str)>>(); 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::<Vec<(uint, &str)>>(); 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(); @@ -2202,14 +2201,14 @@ mod tests { let s = "\n\r\n\r"; let gr = s.graphemes(true).rev().collect::<Vec<&str>>(); 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 fbb0bb5c4ce..571f3fa4685 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::<Vec<u16>>(); + let s_as_utf16 = s.utf16_units().collect::<Vec<u16>>(); 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::<Vec<u16>>(), u); + assert_eq!(u_as_string.utf16_units().collect::<Vec<u16>>(), 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'); } @@ -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<int> = 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 119268c27ee..3818be5a197 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 cf6a534cf19..15bf4988619 100644 --- a/src/libcollections/tree/set.rs +++ b/src/libcollections/tree/set.rs @@ -1103,7 +1103,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 672ddab4d87..6491c9a569d 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 1b3657943da..436da511742 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.rs b/src/libcollections/vec.rs index 2396cf8cec6..c77ef86697b 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -211,7 +211,7 @@ impl<T> Vec<T> { 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<T: Clone> Vec<T> { 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<T: Clone> Vec<T> { // 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); } @@ -798,7 +798,7 @@ impl<T> Vec<T> { // 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)); } } } @@ -896,7 +896,7 @@ impl<T> Vec<T> { pub fn swap_remove(&mut self, index: uint) -> Option<T> { 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 } @@ -1091,7 +1091,7 @@ impl<T> Vec<T> { } else { unsafe { self.len -= 1; - Some(ptr::read(self.as_slice().unsafe_get(self.len()))) + Some(ptr::read(self.unsafe_get(self.len()))) } } } @@ -1231,7 +1231,7 @@ impl<T: PartialEq> Vec<T> { 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<T> Drop for Vec<T> { // 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) @@ -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 986e7ef5bc2..97b80108d76 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -870,9 +870,8 @@ 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()); + assert_eq!(format!("{}", empty), "{}"); } #[test] |
