From 37a94b80f207e86017e54056ced2dc9674907ae3 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Mon, 4 Aug 2014 14:19:02 +0200 Subject: [PATCH] Use temp vars for implicit coercion to ^[T] --- src/libcollections/bitv.rs | 2 +- src/libcollections/dlist.rs | 3 +- src/libcollections/hash/mod.rs | 3 +- src/libcollections/hash/sip.rs | 4 +- src/libcollections/ringbuf.rs | 18 +- src/libcollections/slice.rs | 219 ++++++++++++------ src/libcollections/str.rs | 50 ++-- src/libcollections/treemap.rs | 3 +- src/libcore/option.rs | 10 +- src/libcore/str.rs | 19 +- src/libnum/bigint.rs | 6 +- src/librand/isaac.rs | 18 +- src/librand/lib.rs | 6 +- src/libserialize/hex.rs | 5 +- src/libstd/ascii.rs | 12 +- src/libstd/io/buffered.rs | 62 +++-- src/libstd/io/comm_adapters.rs | 13 +- src/libstd/io/mem.rs | 38 +-- src/libstd/io/result.rs | 3 +- src/libstd/os.rs | 3 +- src/libstd/path/mod.rs | 5 +- src/libstd/rand/mod.rs | 9 +- src/test/bench/core-map.rs | 3 +- src/test/bench/core-set.rs | 2 +- src/test/run-pass/byte-literals.rs | 22 +- src/test/run-pass/running-with-no-runtime.rs | 24 +- src/test/run-pass/syntax-extension-bytes.rs | 12 +- .../run-pass/typeck_type_placeholder_1.rs | 5 +- .../vec-matching-legal-tail-element-borrow.rs | 1 + src/test/run-pass/vec-matching.rs | 9 +- src/test/run-pass/vec-to_str.rs | 7 +- 31 files changed, 381 insertions(+), 215 deletions(-) diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index 10ebcbcab36..d13767077c7 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -2557,7 +2557,7 @@ mod tests { } fn rng() -> rand::IsaacRng { - let seed = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; + let seed: &[_] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; rand::SeedableRng::from_seed(seed) } diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 2899bdc0ddb..418bb147d20 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -1088,7 +1088,8 @@ mod tests { let n = list_from([1i,2,3]); spawn(proc() { check_links(&n); - assert_eq!(&[&1,&2,&3], n.iter().collect::>().as_slice()); + let a: &[_] = &[&1,&2,&3]; + assert_eq!(a, n.iter().collect::>().as_slice()); }); } diff --git a/src/libcollections/hash/mod.rs b/src/libcollections/hash/mod.rs index b867bb7be04..ef26452a529 100644 --- a/src/libcollections/hash/mod.rs +++ b/src/libcollections/hash/mod.rs @@ -346,7 +346,8 @@ mod tests { assert_eq!(hasher.hash(&'a'), 97); assert_eq!(hasher.hash(&("a")), 97 + 0xFF); - assert_eq!(hasher.hash(& &[1u8, 2u8, 3u8]), 9); + let cs: &[u8] = &[1u8, 2u8, 3u8]; + assert_eq!(hasher.hash(& cs), 9); unsafe { let ptr: *const int = mem::transmute(5i); diff --git a/src/libcollections/hash/sip.rs b/src/libcollections/hash/sip.rs index 09a0edd9e3a..f3798e5f9e0 100644 --- a/src/libcollections/hash/sip.rs +++ b/src/libcollections/hash/sip.rs @@ -495,8 +495,8 @@ mod tests { assert!(s != t && t != u); assert!(hash(&s) != hash(&t) && hash(&s) != hash(&u)); - let v = (&[1u8], &[0u8, 0], &[0u8]); - let w = (&[1u8, 0, 0, 0], &[], &[]); + let v: (&[u8], &[u8], &[u8]) = (&[1u8], &[0u8, 0], &[0u8]); + let w: (&[u8], &[u8], &[u8]) = (&[1u8, 0, 0, 0], &[], &[]); assert!(v != w); assert!(hash(&v) != hash(&w)); diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index c9b60e67edd..d2cfb510bc0 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -865,12 +865,18 @@ mod tests { for i in range(0i, 5) { d.push_back(i); } - assert_eq!(d.iter().collect::>().as_slice(), &[&0,&1,&2,&3,&4]); + { + let b: &[_] = &[&0,&1,&2,&3,&4]; + assert_eq!(d.iter().collect::>().as_slice(), b); + } for i in range(6i, 9) { d.push_front(i); } - assert_eq!(d.iter().collect::>().as_slice(), &[&8,&7,&6,&0,&1,&2,&3,&4]); + { + let b: &[_] = &[&8,&7,&6,&0,&1,&2,&3,&4]; + assert_eq!(d.iter().collect::>().as_slice(), b); + } let mut it = d.iter(); let mut len = d.len(); @@ -890,12 +896,16 @@ mod tests { for i in range(0i, 5) { d.push_back(i); } - assert_eq!(d.iter().rev().collect::>().as_slice(), &[&4,&3,&2,&1,&0]); + { + let b: &[_] = &[&4,&3,&2,&1,&0]; + assert_eq!(d.iter().rev().collect::>().as_slice(), b); + } for i in range(6i, 9) { d.push_front(i); } - assert_eq!(d.iter().rev().collect::>().as_slice(), &[&4,&3,&2,&1,&0,&6,&7,&8]); + let b: &[_] = &[&4,&3,&2,&1,&0,&6,&7,&8]; + assert_eq!(d.iter().rev().collect::>().as_slice(), b); } #[test] diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index bd8e18d1f3c..55723ec10a0 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -698,11 +698,13 @@ pub trait MutableOrdSlice { /// # Example /// /// ```rust - /// let v = &mut [0i, 1, 2]; + /// let v: &mut [_] = &mut [0i, 1, 2]; /// v.next_permutation(); - /// assert_eq!(v, &mut [0i, 2, 1]); + /// let b: &mut [_] = &mut [0i, 2, 1]; + /// assert!(v == b); /// v.next_permutation(); - /// assert_eq!(v, &mut [1i, 0, 2]); + /// let b: &mut [_] = &mut [1i, 0, 2]; + /// assert!(v == b); /// ``` fn next_permutation(self) -> bool; @@ -714,11 +716,13 @@ pub trait MutableOrdSlice { /// # Example /// /// ```rust - /// let v = &mut [1i, 0, 2]; + /// let v: &mut [_] = &mut [1i, 0, 2]; /// v.prev_permutation(); - /// assert_eq!(v, &mut [0i, 2, 1]); + /// let b: &mut [_] = &mut [0i, 2, 1]; + /// assert!(v == b); /// v.prev_permutation(); - /// assert_eq!(v, &mut [0i, 1, 2]); + /// let b: &mut [_] = &mut [0i, 1, 2]; + /// assert!(v == b); /// ``` fn prev_permutation(self) -> bool; } @@ -905,9 +909,11 @@ mod tests { #[test] fn test_tail() { let mut a = vec![11i]; - assert_eq!(a.tail(), &[]); + let b: &[int] = &[]; + assert_eq!(a.tail(), b); a = vec![11i, 12]; - assert_eq!(a.tail(), &[12]); + let b: &[int] = &[12]; + assert_eq!(a.tail(), b); } #[test] @@ -920,9 +926,11 @@ mod tests { #[test] fn test_tailn() { let mut a = vec![11i, 12, 13]; - assert_eq!(a.tailn(0), &[11, 12, 13]); + let b: &[int] = &[11, 12, 13]; + assert_eq!(a.tailn(0), b); a = vec![11i, 12, 13]; - assert_eq!(a.tailn(2), &[13]); + let b: &[int] = &[13]; + assert_eq!(a.tailn(2), b); } #[test] @@ -935,9 +943,11 @@ mod tests { #[test] fn test_init() { let mut a = vec![11i]; - assert_eq!(a.init(), &[]); + let b: &[int] = &[]; + assert_eq!(a.init(), b); a = vec![11i, 12]; - assert_eq!(a.init(), &[11]); + let b: &[int] = &[11]; + assert_eq!(a.init(), b); } #[test] @@ -950,9 +960,11 @@ mod tests { #[test] fn test_initn() { let mut a = vec![11i, 12, 13]; - assert_eq!(a.as_slice().initn(0), &[11, 12, 13]); + let b: &[int] = &[11, 12, 13]; + assert_eq!(a.as_slice().initn(0), b); a = vec![11i, 12, 13]; - assert_eq!(a.as_slice().initn(2), &[11]); + let b: &[int] = &[11]; + assert_eq!(a.as_slice().initn(2), b); } #[test] @@ -1005,18 +1017,22 @@ mod tests { #[test] fn test_slice_from() { - let vec = &[1i, 2, 3, 4]; + let vec: &[int] = &[1, 2, 3, 4]; assert_eq!(vec.slice_from(0), vec); - assert_eq!(vec.slice_from(2), &[3, 4]); - assert_eq!(vec.slice_from(4), &[]); + let b: &[int] = &[3, 4]; + assert_eq!(vec.slice_from(2), b); + let b: &[int] = &[]; + assert_eq!(vec.slice_from(4), b); } #[test] fn test_slice_to() { - let vec = &[1i, 2, 3, 4]; + let vec: &[int] = &[1, 2, 3, 4]; assert_eq!(vec.slice_to(4), vec); - assert_eq!(vec.slice_to(2), &[1, 2]); - assert_eq!(vec.slice_to(0), &[]); + let b: &[int] = &[1, 2]; + assert_eq!(vec.slice_to(2), b); + let b: &[int] = &[]; + assert_eq!(vec.slice_to(0), b); } @@ -1270,23 +1286,30 @@ mod tests { let v : &mut[int] = &mut[1i, 2, 3, 4, 5]; assert!(v.prev_permutation() == false); assert!(v.next_permutation()); - assert_eq!(v, &mut[1, 2, 3, 5, 4]); + let b: &mut[int] = &mut[1, 2, 3, 5, 4]; + assert!(v == b); assert!(v.prev_permutation()); - assert_eq!(v, &mut[1, 2, 3, 4, 5]); + let b: &mut[int] = &mut[1, 2, 3, 4, 5]; + assert!(v == b); assert!(v.next_permutation()); assert!(v.next_permutation()); - assert_eq!(v, &mut[1, 2, 4, 3, 5]); + let b: &mut[int] = &mut[1, 2, 4, 3, 5]; + assert!(v == b); assert!(v.next_permutation()); - assert_eq!(v, &mut[1, 2, 4, 5, 3]); + let b: &mut[int] = &mut[1, 2, 4, 5, 3]; + assert!(v == b); let v : &mut[int] = &mut[1i, 0, 0, 0]; assert!(v.next_permutation() == false); assert!(v.prev_permutation()); - assert_eq!(v, &mut[0, 1, 0, 0]); + let b: &mut[int] = &mut[0, 1, 0, 0]; + assert!(v == b); assert!(v.prev_permutation()); - assert_eq!(v, &mut[0, 0, 1, 0]); + let b: &mut[int] = &mut[0, 0, 1, 0]; + assert!(v == b); assert!(v.prev_permutation()); - assert_eq!(v, &mut[0, 0, 0, 1]); + let b: &mut[int] = &mut[0, 0, 0, 1]; + assert!(v == b); assert!(v.prev_permutation() == false); } @@ -1294,27 +1317,31 @@ mod tests { fn test_lexicographic_permutations_empty_and_short() { let empty : &mut[int] = &mut[]; assert!(empty.next_permutation() == false); - assert_eq!(empty, &mut[]); + let b: &mut[int] = &mut[]; + assert!(empty == b); assert!(empty.prev_permutation() == false); - assert_eq!(empty, &mut[]); + assert!(empty == b); let one_elem : &mut[int] = &mut[4i]; assert!(one_elem.prev_permutation() == false); - assert_eq!(one_elem, &mut[4]); + let b: &mut[int] = &mut[4]; + assert!(one_elem == b); assert!(one_elem.next_permutation() == false); - assert_eq!(one_elem, &mut[4]); + assert!(one_elem == b); let two_elem : &mut[int] = &mut[1i, 2]; assert!(two_elem.prev_permutation() == false); - assert_eq!(two_elem, &mut[1, 2]); + let b : &mut[int] = &mut[1, 2]; + let c : &mut[int] = &mut[2, 1]; + assert!(two_elem == b); assert!(two_elem.next_permutation()); - assert_eq!(two_elem, &mut[2, 1]); + assert!(two_elem == c); assert!(two_elem.next_permutation() == false); - assert_eq!(two_elem, &mut[2, 1]); + assert!(two_elem == c); assert!(two_elem.prev_permutation()); - assert_eq!(two_elem, &mut[1, 2]); + assert!(two_elem == b); assert!(two_elem.prev_permutation() == false); - assert_eq!(two_elem, &mut[1, 2]); + assert!(two_elem == b); } #[test] @@ -1468,7 +1495,10 @@ mod tests { assert_eq!(v.concat_vec(), vec![]); assert_eq!([vec![1i], vec![2i,3i]].concat_vec(), vec![1, 2, 3]); - assert_eq!([&[1i], &[2i,3i]].concat_vec(), vec![1, 2, 3]); + let v: [&[int], ..2] = [&[1], &[2, 3]]; + assert_eq!(v.connect_vec(&0), vec![1, 0, 2, 3]); + let v: [&[int], ..3] = [&[1], &[2], &[3]]; + assert_eq!(v.connect_vec(&0), vec![1, 0, 2, 0, 3]); } #[test] @@ -1478,8 +1508,10 @@ mod tests { assert_eq!([vec![1i], vec![2i, 3]].connect_vec(&0), vec![1, 0, 2, 3]); assert_eq!([vec![1i], vec![2i], vec![3i]].connect_vec(&0), vec![1, 0, 2, 0, 3]); - assert_eq!([&[1i], &[2i, 3]].connect_vec(&0), vec![1, 0, 2, 3]); - assert_eq!([&[1i], &[2i], &[3]].connect_vec(&0), vec![1, 0, 2, 0, 3]); + let v: [&[int], ..2] = [&[1], &[2, 3]]; + assert_eq!(v.connect_vec(&0), vec![1, 0, 2, 3]); + let v: [&[int], ..3] = [&[1], &[2], &[3]]; + assert_eq!(v.connect_vec(&0), vec![1, 0, 2, 0, 3]); } #[test] @@ -1637,11 +1669,16 @@ mod tests { #[test] fn test_total_ord() { - [1i, 2, 3, 4].cmp(& &[1, 2, 3]) == Greater; - [1i, 2, 3].cmp(& &[1, 2, 3, 4]) == Less; - [1i, 2, 3, 4].cmp(& &[1, 2, 3, 4]) == Equal; - [1i, 2, 3, 4, 5, 5, 5, 5].cmp(& &[1, 2, 3, 4, 5, 6]) == Less; - [2i, 2].cmp(& &[1, 2, 3, 4]) == Greater; + let c: &[int] = &[1, 2, 3]; + [1, 2, 3, 4].cmp(& c) == Greater; + let c: &[int] = &[1, 2, 3, 4]; + [1, 2, 3].cmp(& c) == Less; + let c: &[int] = &[1, 2, 3, 6]; + [1, 2, 3, 4].cmp(& c) == Equal; + let c: &[int] = &[1, 2, 3, 4, 5, 6]; + [1, 2, 3, 4, 5, 5, 5, 5].cmp(& c) == Less; + let c: &[int] = &[1, 2, 3, 4]; + [2, 2].cmp(& c) == Greater; } #[test] @@ -1765,74 +1802,95 @@ mod tests { fn test_splitator() { let xs = &[1i,2,3,4,5]; + let splits: &[&[int]] = &[&[1], &[3], &[5]]; assert_eq!(xs.split(|x| *x % 2 == 0).collect::>().as_slice(), - &[&[1], &[3], &[5]]); + splits); + let splits: &[&[int]] = &[&[], &[2,3,4,5]]; assert_eq!(xs.split(|x| *x == 1).collect::>().as_slice(), - &[&[], &[2,3,4,5]]); + splits); + let splits: &[&[int]] = &[&[1,2,3,4], &[]]; assert_eq!(xs.split(|x| *x == 5).collect::>().as_slice(), - &[&[1,2,3,4], &[]]); + splits); + let splits: &[&[int]] = &[&[1,2,3,4,5]]; assert_eq!(xs.split(|x| *x == 10).collect::>().as_slice(), - &[&[1,2,3,4,5]]); + splits); + let splits: &[&[int]] = &[&[], &[], &[], &[], &[], &[]]; assert_eq!(xs.split(|_| true).collect::>().as_slice(), - &[&[], &[], &[], &[], &[], &[]]); + splits); let xs: &[int] = &[]; - assert_eq!(xs.split(|x| *x == 5).collect::>().as_slice(), &[&[]]); + let splits: &[&[int]] = &[&[]]; + assert_eq!(xs.split(|x| *x == 5).collect::>().as_slice(), splits); } #[test] fn test_splitnator() { 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(), - &[&[1,2,3,4,5]]); + splits); + let splits: &[&[int]] = &[&[1], &[3,4,5]]; assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::>().as_slice(), - &[&[1], &[3,4,5]]); + splits); + let splits: &[&[int]] = &[&[], &[], &[], &[4,5]]; assert_eq!(xs.splitn(3, |_| true).collect::>().as_slice(), - &[&[], &[], &[], &[4,5]]); + splits); let xs: &[int] = &[]; - assert_eq!(xs.splitn(1, |x| *x == 5).collect::>().as_slice(), &[&[]]); + let splits: &[&[int]] = &[&[]]; + assert_eq!(xs.splitn(1, |x| *x == 5).collect::>().as_slice(), splits); } #[test] fn test_rsplitator() { 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(), - &[&[5], &[3], &[1]]); + splits); + let splits: &[&[int]] = &[&[2,3,4,5], &[]]; assert_eq!(xs.split(|x| *x == 1).rev().collect::>().as_slice(), - &[&[2,3,4,5], &[]]); + splits); + let splits: &[&[int]] = &[&[], &[1,2,3,4]]; assert_eq!(xs.split(|x| *x == 5).rev().collect::>().as_slice(), - &[&[], &[1,2,3,4]]); + splits); + let splits: &[&[int]] = &[&[1,2,3,4,5]]; assert_eq!(xs.split(|x| *x == 10).rev().collect::>().as_slice(), - &[&[1,2,3,4,5]]); + splits); let xs: &[int] = &[]; - assert_eq!(xs.split(|x| *x == 5).rev().collect::>().as_slice(), &[&[]]); + let splits: &[&[int]] = &[&[]]; + assert_eq!(xs.split(|x| *x == 5).rev().collect::>().as_slice(), splits); } #[test] fn test_rsplitnator() { 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(), - &[&[1,2,3,4,5]]); + splits); + let splits: &[&[int]] = &[&[5], &[1,2,3]]; assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::>().as_slice(), - &[&[5], &[1,2,3]]); + splits); + let splits: &[&[int]] = &[&[], &[], &[], &[1,2]]; assert_eq!(xs.rsplitn(3, |_| true).collect::>().as_slice(), - &[&[], &[], &[], &[1,2]]); + splits); let xs: &[int] = &[]; - assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::>().as_slice(), &[&[]]); + let splits: &[&[int]] = &[&[]]; + assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::>().as_slice(), splits); } #[test] fn test_windowsator() { let v = &[1i,2,3,4]; - assert_eq!(v.windows(2).collect::>().as_slice(), &[&[1,2], &[2,3], &[3,4]]); - assert_eq!(v.windows(3).collect::>().as_slice(), &[&[1i,2,3], &[2,3,4]]); + let wins: &[&[int]] = &[&[1,2], &[2,3], &[3,4]]; + assert_eq!(v.windows(2).collect::>().as_slice(), wins); + let wins: &[&[int]] = &[&[1i,2,3], &[2,3,4]]; + assert_eq!(v.windows(3).collect::>().as_slice(), wins); assert!(v.windows(6).next().is_none()); } @@ -1847,16 +1905,23 @@ mod tests { fn test_chunksator() { let v = &[1i,2,3,4,5]; - assert_eq!(v.chunks(2).collect::>().as_slice(), &[&[1i,2], &[3,4], &[5]]); - assert_eq!(v.chunks(3).collect::>().as_slice(), &[&[1i,2,3], &[4,5]]); - assert_eq!(v.chunks(6).collect::>().as_slice(), &[&[1i,2,3,4,5]]); + let chunks: &[&[int]] = &[&[1i,2], &[3,4], &[5]]; + assert_eq!(v.chunks(2).collect::>().as_slice(), chunks); + let chunks: &[&[int]] = &[&[1i,2,3], &[4,5]]; + assert_eq!(v.chunks(3).collect::>().as_slice(), chunks); + let chunks: &[&[int]] = &[&[1i,2,3,4,5]]; + assert_eq!(v.chunks(6).collect::>().as_slice(), chunks); - assert_eq!(v.chunks(2).rev().collect::>().as_slice(), &[&[5i], &[3,4], &[1,2]]); + let chunks: &[&[int]] = &[&[5i], &[3,4], &[1,2]]; + assert_eq!(v.chunks(2).rev().collect::>().as_slice(), chunks); let mut it = v.chunks(2); assert_eq!(it.indexable(), 3); - assert_eq!(it.idx(0).unwrap(), &[1,2]); - assert_eq!(it.idx(1).unwrap(), &[3,4]); - assert_eq!(it.idx(2).unwrap(), &[5]); + let chunk: &[int] = &[1,2]; + assert_eq!(it.idx(0).unwrap(), chunk); + let chunk: &[int] = &[3,4]; + assert_eq!(it.idx(1).unwrap(), chunk); + let chunk: &[int] = &[5]; + assert_eq!(it.idx(2).unwrap(), chunk); assert_eq!(it.idx(3), None); } @@ -1924,10 +1989,12 @@ mod tests { let empty_mut: &mut [int] = &mut[]; test_show_vec!(empty_mut, "[]".to_string()); - test_show_vec!(&mut[1i], "[1]".to_string()); - test_show_vec!(&mut[1i, 2, 3], "[1, 2, 3]".to_string()); - test_show_vec!(&mut[&mut[], &mut[1u], &mut[1u, 1u]], - "[[], [1], [1, 1]]".to_string()); + let v: &mut[int] = &mut[1]; + test_show_vec!(v, "[1]".to_string()); + let v: &mut[int] = &mut[1, 2, 3]; + test_show_vec!(v, "[1, 2, 3]".to_string()); + let v: &mut [&mut[uint]] = &mut[&mut[], &mut[1u], &mut[1u, 1u]]; + test_show_vec!(v, "[[], [1], [1, 1]]".to_string()); } #[test] diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 9120b3889e7..1145e1f3573 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1265,12 +1265,14 @@ mod tests { fn test_trim_left_chars() { let v: &[char] = &[]; assert_eq!(" *** foo *** ".trim_left_chars(v), " *** foo *** "); - assert_eq!(" *** foo *** ".trim_left_chars(&['*', ' ']), "foo *** "); - assert_eq!(" *** *** ".trim_left_chars(&['*', ' ']), ""); - assert_eq!("foo *** ".trim_left_chars(&['*', ' ']), "foo *** "); + let chars: &[char] = &['*', ' ']; + assert_eq!(" *** foo *** ".trim_left_chars(chars), "foo *** "); + assert_eq!(" *** *** ".trim_left_chars(chars), ""); + assert_eq!("foo *** ".trim_left_chars(chars), "foo *** "); assert_eq!("11foo1bar11".trim_left_chars('1'), "foo1bar11"); - assert_eq!("12foo1bar12".trim_left_chars(&['1', '2']), "foo1bar12"); + let chars: &[char] = &['1', '2']; + assert_eq!("12foo1bar12".trim_left_chars(chars), "foo1bar12"); assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_digit()), "foo1bar123"); } @@ -1278,12 +1280,14 @@ mod tests { fn test_trim_right_chars() { let v: &[char] = &[]; assert_eq!(" *** foo *** ".trim_right_chars(v), " *** foo *** "); - assert_eq!(" *** foo *** ".trim_right_chars(&['*', ' ']), " *** foo"); - assert_eq!(" *** *** ".trim_right_chars(&['*', ' ']), ""); - assert_eq!(" *** foo".trim_right_chars(&['*', ' ']), " *** foo"); + let chars: &[char] = &['*', ' ']; + assert_eq!(" *** foo *** ".trim_right_chars(chars), " *** foo"); + assert_eq!(" *** *** ".trim_right_chars(chars), ""); + assert_eq!(" *** foo".trim_right_chars(chars), " *** foo"); assert_eq!("11foo1bar11".trim_right_chars('1'), "11foo1bar"); - assert_eq!("12foo1bar12".trim_right_chars(&['1', '2']), "12foo1bar"); + let chars: &[char] = &['1', '2']; + assert_eq!("12foo1bar12".trim_right_chars(chars), "12foo1bar"); assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_digit()), "123foo1bar"); } @@ -1291,12 +1295,14 @@ mod tests { fn test_trim_chars() { let v: &[char] = &[]; assert_eq!(" *** foo *** ".trim_chars(v), " *** foo *** "); - assert_eq!(" *** foo *** ".trim_chars(&['*', ' ']), "foo"); - assert_eq!(" *** *** ".trim_chars(&['*', ' ']), ""); - assert_eq!("foo".trim_chars(&['*', ' ']), "foo"); + let chars: &[char] = &['*', ' ']; + assert_eq!(" *** foo *** ".trim_chars(chars), "foo"); + assert_eq!(" *** *** ".trim_chars(chars), ""); + assert_eq!("foo".trim_chars(chars), "foo"); assert_eq!("11foo1bar11".trim_chars('1'), "foo1bar"); - assert_eq!("12foo1bar12".trim_chars(&['1', '2']), "foo1bar"); + let chars: &[char] = &['1', '2']; + assert_eq!("12foo1bar12".trim_chars(chars), "foo1bar"); assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_digit()), "foo1bar"); } @@ -1443,7 +1449,8 @@ mod tests { 184, 173, 229, 141, 142, 86, 105, 225, 187, 135, 116, 32, 78, 97, 109 ]; - assert_eq!("".as_bytes(), &[]); + 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()); } @@ -1542,19 +1549,23 @@ mod tests { #[test] fn test_truncate_utf16_at_nul() { let v = []; - assert_eq!(truncate_utf16_at_nul(v), &[]); + let b: &[u16] = &[]; + assert_eq!(truncate_utf16_at_nul(v), b); let v = [0, 2, 3]; - assert_eq!(truncate_utf16_at_nul(v), &[]); + assert_eq!(truncate_utf16_at_nul(v), b); let v = [1, 0, 3]; - assert_eq!(truncate_utf16_at_nul(v), &[1]); + let b: &[u16] = &[1]; + assert_eq!(truncate_utf16_at_nul(v), b); let v = [1, 2, 0]; - assert_eq!(truncate_utf16_at_nul(v), &[1, 2]); + let b: &[u16] = &[1, 2]; + assert_eq!(truncate_utf16_at_nul(v), b); let v = [1, 2, 3]; - assert_eq!(truncate_utf16_at_nul(v), &[1, 2, 3]); + let b: &[u16] = &[1, 2, 3]; + assert_eq!(truncate_utf16_at_nul(v), b); } #[test] @@ -2494,7 +2505,8 @@ mod bench { let s = "Mary had a little lamb, Little lamb, little-lamb."; let len = s.split(' ').count(); - b.iter(|| assert_eq!(s.split(&[' ']).count(), len)); + let c: &[char] = &[' ']; + b.iter(|| assert_eq!(s.split(c).count(), len)); } #[bench] diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index 4ab33b05aaa..8e5ffbd1686 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -1853,7 +1853,8 @@ mod test_treemap { check_equal(ctrl.as_slice(), &map); assert!(map.find(&5).is_none()); - let mut rng: rand::IsaacRng = rand::SeedableRng::from_seed(&[42]); + let seed: &[_] = &[42]; + let mut rng: rand::IsaacRng = rand::SeedableRng::from_seed(seed); for _ in range(0u, 3) { for _ in range(0u, 90) { diff --git a/src/libcore/option.rs b/src/libcore/option.rs index bf8a92a4f95..47df8ae68cd 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -221,8 +221,14 @@ impl Option { #[inline] pub fn as_mut_slice<'r>(&'r mut self) -> &'r mut [T] { match *self { - Some(ref mut x) => slice::mut_ref_slice(x), - None => &mut [] + Some(ref mut x) => { + let result: &mut [T] = slice::mut_ref_slice(x); + result + } + None => { + let result: &mut [T] = &mut []; + result + } } } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 66564b1bf07..5cbeda94d0f 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -918,8 +918,8 @@ pub fn utf16_items<'a>(v: &'a [u16]) -> Utf16Items<'a> { /// /// // "ab\0d" /// v[2] = 0; -/// assert_eq!(str::truncate_utf16_at_nul(v), -/// &['a' as u16, 'b' as u16]); +/// let b: &[_] = &['a' as u16, 'b' as u16]; +/// assert_eq!(str::truncate_utf16_at_nul(v), b); /// ``` pub fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] { match v.iter().position(|c| *c == 0) { @@ -1439,7 +1439,8 @@ pub trait StrSlice<'a> { /// /// ```rust /// assert_eq!("11foo1bar11".trim_chars('1'), "foo1bar") - /// assert_eq!("12foo1bar12".trim_chars(&['1', '2']), "foo1bar") + /// let x: &[_] = &['1', '2']; + /// assert_eq!("12foo1bar12".trim_chars(x), "foo1bar") /// assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_digit()), "foo1bar") /// ``` fn trim_chars(&self, to_trim: C) -> &'a str; @@ -1454,7 +1455,8 @@ pub trait StrSlice<'a> { /// /// ```rust /// assert_eq!("11foo1bar11".trim_left_chars('1'), "foo1bar11") - /// assert_eq!("12foo1bar12".trim_left_chars(&['1', '2']), "foo1bar12") + /// let x: &[_] = &['1', '2']; + /// assert_eq!("12foo1bar12".trim_left_chars(x), "foo1bar12") /// assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_digit()), "foo1bar123") /// ``` fn trim_left_chars(&self, to_trim: C) -> &'a str; @@ -1469,7 +1471,8 @@ pub trait StrSlice<'a> { /// /// ```rust /// assert_eq!("11foo1bar11".trim_right_chars('1'), "11foo1bar") - /// assert_eq!("12foo1bar12".trim_right_chars(&['1', '2']), "12foo1bar") + /// let x: &[_] = &['1', '2']; + /// assert_eq!("12foo1bar12".trim_right_chars(x), "12foo1bar") /// assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_digit()), "123foo1bar") /// ``` fn trim_right_chars(&self, to_trim: C) -> &'a str; @@ -1620,7 +1623,8 @@ pub trait StrSlice<'a> { /// assert_eq!(s.find(|c: char| c.is_whitespace()), Some(5)); /// /// // neither are found - /// assert_eq!(s.find(&['1', '2']), None); + /// let x: &[_] = &['1', '2']; + /// assert_eq!(s.find(x), None); /// ``` fn find(&self, search: C) -> Option; @@ -1644,7 +1648,8 @@ pub trait StrSlice<'a> { /// assert_eq!(s.rfind(|c: char| c.is_whitespace()), Some(12)); /// /// // searches for an occurrence of either `1` or `2`, but neither are found - /// assert_eq!(s.rfind(&['1', '2']), None); + /// let x: &[_] = &['1', '2']; + /// assert_eq!(s.rfind(x), None); /// ``` fn rfind(&self, search: C) -> Option; diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index 48fc9fb4a38..ba45d2b2e73 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -1449,8 +1449,8 @@ mod biguint_tests { #[test] fn test_cmp() { - let data: Vec = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1] ] - .iter().map(|v| BigUint::from_slice(*v)).collect(); + let data: [&[_], ..7] = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1] ]; + let data: Vec = data.iter().map(|v| BigUint::from_slice(*v)).collect(); for (i, ni) in data.iter().enumerate() { for (j0, nj) in data.slice(i, data.len()).iter().enumerate() { let j = j0 + i; @@ -2311,7 +2311,7 @@ mod bigint_tests { #[test] fn test_cmp() { - let vs = [ &[2 as BigDigit], &[1, 1], &[2, 1], &[1, 1, 1] ]; + let vs: [&[BigDigit], ..4] = [ &[2 as BigDigit], &[1, 1], &[2, 1], &[1, 1, 1] ]; let mut nums = Vec::new(); for s in vs.iter().rev() { nums.push(BigInt::from_slice(Minus, *s)); diff --git a/src/librand/isaac.rs b/src/librand/isaac.rs index 2fbfa6d6e85..0f7cda42a8a 100644 --- a/src/librand/isaac.rs +++ b/src/librand/isaac.rs @@ -13,7 +13,6 @@ use core::prelude::*; use core::iter::{range_step, Repeat}; use core::slice::raw; -use core::mem; use {Rng, SeedableRng, Rand}; @@ -46,6 +45,7 @@ static EMPTY: IsaacRng = IsaacRng { }; impl IsaacRng { + /// Create an ISAAC random number generator using the default /// fixed seed. pub fn new_unseeded() -> IsaacRng { @@ -225,7 +225,7 @@ impl Rand for IsaacRng { let ptr = ret.rsl.as_mut_ptr(); raw::mut_buf_as_slice(ptr as *mut u8, - mem::size_of_val(&ret.rsl), |slice| { + (RAND_SIZE*4) as uint, |slice| { other.fill_bytes(slice); }) } @@ -456,7 +456,7 @@ impl Rand for Isaac64Rng { let ptr = ret.rsl.as_mut_ptr(); raw::mut_buf_as_slice(ptr as *mut u8, - mem::size_of_val(&ret.rsl), |slice| { + (RAND_SIZE_64*8) as uint, |slice| { other.fill_bytes(slice); }) } @@ -497,7 +497,7 @@ mod test { #[test] fn test_rng_32_seeded() { - let seed = &[1, 23, 456, 7890, 12345]; + let seed: &[_] = &[1, 23, 456, 7890, 12345]; let mut ra: IsaacRng = SeedableRng::from_seed(seed); let mut rb: IsaacRng = SeedableRng::from_seed(seed); assert!(order::equals(ra.gen_ascii_chars().take(100), @@ -505,7 +505,7 @@ mod test { } #[test] fn test_rng_64_seeded() { - let seed = &[1, 23, 456, 7890, 12345]; + let seed: &[_] = &[1, 23, 456, 7890, 12345]; let mut ra: Isaac64Rng = SeedableRng::from_seed(seed); let mut rb: Isaac64Rng = SeedableRng::from_seed(seed); assert!(order::equals(ra.gen_ascii_chars().take(100), @@ -537,7 +537,7 @@ mod test { #[test] fn test_rng_32_true_values() { - let seed = &[1, 23, 456, 7890, 12345]; + let seed: &[_] = &[1, 23, 456, 7890, 12345]; let mut ra: IsaacRng = SeedableRng::from_seed(seed); // Regression test that isaac is actually using the above vector let v = Vec::from_fn(10, |_| ra.next_u32()); @@ -545,7 +545,7 @@ mod test { vec!(2558573138, 873787463, 263499565, 2103644246, 3595684709, 4203127393, 264982119, 2765226902, 2737944514, 3900253796)); - let seed = &[12345, 67890, 54321, 9876]; + let seed: &[_] = &[12345, 67890, 54321, 9876]; let mut rb: IsaacRng = SeedableRng::from_seed(seed); // skip forward to the 10000th number for _ in range(0u, 10000) { rb.next_u32(); } @@ -557,7 +557,7 @@ mod test { } #[test] fn test_rng_64_true_values() { - let seed = &[1, 23, 456, 7890, 12345]; + let seed: &[_] = &[1, 23, 456, 7890, 12345]; let mut ra: Isaac64Rng = SeedableRng::from_seed(seed); // Regression test that isaac is actually using the above vector let v = Vec::from_fn(10, |_| ra.next_u64()); @@ -567,7 +567,7 @@ mod test { 4469761996653280935, 15552757044682284409, 6860251611068737823, 13722198873481261842)); - let seed = &[12345, 67890, 54321, 9876]; + let seed: &[_] = &[12345, 67890, 54321, 9876]; let mut rb: Isaac64Rng = SeedableRng::from_seed(seed); // skip forward to the 10000th number for _ in range(0u, 10000) { rb.next_u64(); } diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 9c33b713e4a..5f460225d39 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -309,7 +309,8 @@ pub trait SeedableRng: Rng { /// ```rust /// use std::rand::{Rng, SeedableRng, StdRng}; /// - /// let mut rng: StdRng = SeedableRng::from_seed(&[1, 2, 3, 4]); + /// let seed: &[_] = &[1, 2, 3, 4]; + /// let mut rng: StdRng = SeedableRng::from_seed(seed); /// println!("{}", rng.gen::()); /// rng.reseed([5, 6, 7, 8]); /// println!("{}", rng.gen::()); @@ -323,7 +324,8 @@ pub trait SeedableRng: Rng { /// ```rust /// use std::rand::{Rng, SeedableRng, StdRng}; /// - /// let mut rng: StdRng = SeedableRng::from_seed(&[1, 2, 3, 4]); + /// let seed: &[_] = &[1, 2, 3, 4]; + /// let mut rng: StdRng = SeedableRng::from_seed(seed); /// println!("{}", rng.gen::()); /// ``` fn from_seed(seed: Seed) -> Self; diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index f33ecb5f19b..1d2fcc8b77b 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -183,16 +183,17 @@ mod tests { #[test] 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(), - &[i as u8]); + ii); assert_eq!(format!("{:02X}", i as uint).as_slice() .from_hex() .unwrap() .as_slice(), - &[i as u8]); + ii); } } diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index b31baa88e0c..f7b23163dfe 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -609,11 +609,12 @@ mod tests { #[test] fn test_ascii_vec() { let test = &[40u8, 32u8, 59u8]; - assert_eq!(test.to_ascii(), v2ascii!([40, 32, 59])); - assert_eq!("( ;".to_ascii(), v2ascii!([40, 32, 59])); + let b: &[_] = v2ascii!([40, 32, 59]); + assert_eq!(test.to_ascii(), b); + assert_eq!("( ;".to_ascii(), b); let v = vec![40u8, 32u8, 59u8]; - assert_eq!(v.as_slice().to_ascii(), v2ascii!([40, 32, 59])); - assert_eq!("( ;".to_string().as_slice().to_ascii(), v2ascii!([40, 32, 59])); + assert_eq!(v.as_slice().to_ascii(), b); + assert_eq!("( ;".to_string().as_slice().to_ascii(), b); assert_eq!("abCDef&?#".to_ascii().to_lower().into_string(), "abcdef&?#".to_string()); assert_eq!("abCDef&?#".to_ascii().to_upper().into_string(), "ABCDEF&?#".to_string()); @@ -688,13 +689,12 @@ mod tests { assert_eq!((test1).to_ascii_opt(), None); let v = [40u8, 32u8, 59u8]; - let v2 = v2ascii!(&[40, 32, 59]); + let v2: &[_] = v2ascii!(&[40, 32, 59]); assert_eq!(v.to_ascii_opt(), Some(v2)); let v = [127u8, 128u8, 255u8]; assert_eq!(v.to_ascii_opt(), None); let v = "( ;"; - let v2 = v2ascii!(&[40, 32, 59]); assert_eq!(v.to_ascii_opt(), Some(v2)); assert_eq!("zoä华".to_ascii_opt(), None); diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index a9b0b33c59a..1d638e498d4 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -415,21 +415,25 @@ mod test { let mut buf = [0, 0, 0]; let nread = reader.read(buf); assert_eq!(Ok(2), nread); - assert_eq!(buf.as_slice(), &[0, 1, 0]); + let b: &[_] = &[0, 1, 0]; + assert_eq!(buf.as_slice(), b); let mut buf = [0]; let nread = reader.read(buf); assert_eq!(Ok(1), nread); - assert_eq!(buf.as_slice(), &[2]); + let b: &[_] = &[2]; + assert_eq!(buf.as_slice(), b); let mut buf = [0, 0, 0]; let nread = reader.read(buf); assert_eq!(Ok(1), nread); - assert_eq!(buf.as_slice(), &[3, 0, 0]); + let b: &[_] = &[3, 0, 0]; + assert_eq!(buf.as_slice(), b); let nread = reader.read(buf); assert_eq!(Ok(1), nread); - assert_eq!(buf.as_slice(), &[4, 0, 0]); + let b: &[_] = &[4, 0, 0]; + assert_eq!(buf.as_slice(), b); assert!(reader.read(buf).is_err()); } @@ -440,35 +444,41 @@ mod test { let mut writer = BufferedWriter::with_capacity(2, inner); writer.write([0, 1]).unwrap(); - assert_eq!(writer.get_ref().get_ref(), &[]); + let b: &[_] = &[]; + assert_eq!(writer.get_ref().get_ref(), b); writer.write([2]).unwrap(); - assert_eq!(writer.get_ref().get_ref(), &[0, 1]); + let b: &[_] = &[0, 1]; + assert_eq!(writer.get_ref().get_ref(), b); writer.write([3]).unwrap(); - assert_eq!(writer.get_ref().get_ref(), &[0, 1]); + assert_eq!(writer.get_ref().get_ref(), b); writer.flush().unwrap(); - assert_eq!(&[0, 1, 2, 3], writer.get_ref().get_ref()); + let a: &[_] = &[0, 1, 2, 3]; + assert_eq!(a, writer.get_ref().get_ref()); writer.write([4]).unwrap(); writer.write([5]).unwrap(); - assert_eq!(&[0, 1, 2, 3], writer.get_ref().get_ref()); + assert_eq!(a, writer.get_ref().get_ref()); writer.write([6]).unwrap(); - assert_eq!(&[0, 1, 2, 3, 4, 5], + let a: &[_] = &[0, 1, 2, 3, 4, 5]; + assert_eq!(a, writer.get_ref().get_ref()); writer.write([7, 8]).unwrap(); - assert_eq!(&[0, 1, 2, 3, 4, 5, 6], + let a: &[_] = &[0, 1, 2, 3, 4, 5, 6]; + assert_eq!(a, writer.get_ref().get_ref()); writer.write([9, 10, 11]).unwrap(); - assert_eq!(&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], + let a: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; + assert_eq!(a, writer.get_ref().get_ref()); writer.flush().unwrap(); - assert_eq!(&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], + assert_eq!(a, writer.get_ref().get_ref()); } @@ -476,9 +486,11 @@ mod test { fn test_buffered_writer_inner_flushes() { let mut w = BufferedWriter::with_capacity(3, MemWriter::new()); w.write([0, 1]).unwrap(); - assert_eq!(&[], w.get_ref().get_ref()); + let a: &[_] = &[]; + assert_eq!(a, w.get_ref().get_ref()); let w = w.unwrap(); - assert_eq!(&[0, 1], w.get_ref()); + let a: &[_] = &[0, 1]; + assert_eq!(a, w.get_ref()); } // This is just here to make sure that we don't infinite loop in the @@ -519,20 +531,22 @@ mod test { fn test_line_buffer() { let mut writer = LineBufferedWriter::new(MemWriter::new()); writer.write([0]).unwrap(); - assert_eq!(writer.get_ref().get_ref(), &[]); + let b: &[_] = &[]; + assert_eq!(writer.get_ref().get_ref(), b); writer.write([1]).unwrap(); - assert_eq!(writer.get_ref().get_ref(), &[]); + assert_eq!(writer.get_ref().get_ref(), b); writer.flush().unwrap(); - assert_eq!(writer.get_ref().get_ref(), &[0, 1]); + let b: &[_] = &[0, 1]; + assert_eq!(writer.get_ref().get_ref(), b); writer.write([0, b'\n', 1, b'\n', 2]).unwrap(); - assert_eq!(writer.get_ref().get_ref(), - &[0, 1, 0, b'\n', 1, b'\n']); + let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n']; + assert_eq!(writer.get_ref().get_ref(), b); writer.flush().unwrap(); - assert_eq!(writer.get_ref().get_ref(), - &[0, 1, 0, b'\n', 1, b'\n', 2]); + let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n', 2]; + assert_eq!(writer.get_ref().get_ref(), b); writer.write([3, b'\n']).unwrap(); - assert_eq!(writer.get_ref().get_ref(), - &[0, 1, 0, b'\n', 1, b'\n', 2, 3, b'\n']); + let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n', 2, 3, b'\n']; + assert_eq!(writer.get_ref().get_ref(), b); } #[test] diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index 53b5fbe3894..1c8b047f56f 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -154,26 +154,29 @@ mod test { assert_eq!(Ok(0), reader.read([])); assert_eq!(Ok(3), reader.read(buf)); - assert_eq!(&[1,2,3], buf.as_slice()); + let a: &[u8] = &[1,2,3]; + assert_eq!(a, buf.as_slice()); assert_eq!(Ok(3), reader.read(buf)); - assert_eq!(&[4,5,6], buf.as_slice()); + let a: &[u8] = &[4,5,6]; + assert_eq!(a, buf.as_slice()); assert_eq!(Ok(2), reader.read(buf)); - assert_eq!(&[7,8,6], buf.as_slice()); + let a: &[u8] = &[7,8,6]; + assert_eq!(a, buf.as_slice()); match reader.read(buf.as_mut_slice()) { Ok(..) => fail!(), Err(e) => assert_eq!(e.kind, io::EndOfFile), } - assert_eq!(&[7,8,6], buf.as_slice()); + assert_eq!(a, buf.as_slice()); // Ensure it continues to fail in the same way. match reader.read(buf.as_mut_slice()) { Ok(..) => fail!(), Err(e) => assert_eq!(e.kind, io::EndOfFile), } - assert_eq!(&[7,8,6], buf.as_slice()); + assert_eq!(a, buf.as_slice()); } #[test] diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index ea9d08171e6..21ab9c1fdd4 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -346,7 +346,8 @@ mod test { writer.write([0]).unwrap(); writer.write([1, 2, 3]).unwrap(); writer.write([4, 5, 6, 7]).unwrap(); - assert_eq!(writer.get_ref(), &[0, 1, 2, 3, 4, 5, 6, 7]); + let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7]; + assert_eq!(writer.get_ref(), b); } #[test] @@ -363,7 +364,8 @@ mod test { writer.write([]).unwrap(); assert_eq!(writer.tell(), Ok(8)); } - assert_eq!(buf.as_slice(), &[0, 1, 2, 3, 4, 5, 6, 7]); + let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7]; + assert_eq!(buf.as_slice(), b); } #[test] @@ -391,7 +393,8 @@ mod test { assert_eq!(writer.tell(), Ok(8)); } - assert_eq!(buf.as_slice(), &[1, 3, 2, 0, 0, 0, 0, 4]); + let b: &[_] = &[1, 3, 2, 0, 0, 0, 0, 4]; + assert_eq!(buf.as_slice(), b); } #[test] @@ -415,13 +418,16 @@ mod test { let mut buf = [0]; assert_eq!(reader.read(buf), Ok(1)); assert_eq!(reader.tell(), Ok(1)); - assert_eq!(buf.as_slice(), &[0]); + let b: &[_] = &[0]; + assert_eq!(buf.as_slice(), b); let mut buf = [0, ..4]; assert_eq!(reader.read(buf), Ok(4)); assert_eq!(reader.tell(), Ok(5)); - assert_eq!(buf.as_slice(), &[1, 2, 3, 4]); + let b: &[_] = &[1, 2, 3, 4]; + assert_eq!(buf.as_slice(), b); assert_eq!(reader.read(buf), Ok(3)); - assert_eq!(buf.slice(0, 3), &[5, 6, 7]); + let b: &[_] = &[5, 6, 7]; + assert_eq!(buf.slice(0, 3), b); assert!(reader.read(buf).is_err()); let mut reader = MemReader::new(vec!(0, 1, 2, 3, 4, 5, 6, 7)); assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3)); @@ -439,13 +445,16 @@ mod test { let mut buf = [0]; assert_eq!(reader.read(buf), Ok(1)); assert_eq!(reader.tell(), Ok(1)); - assert_eq!(buf.as_slice(), &[0]); + let b: &[_] = &[0]; + assert_eq!(buf.as_slice(), b); let mut buf = [0, ..4]; assert_eq!(reader.read(buf), Ok(4)); assert_eq!(reader.tell(), Ok(5)); - assert_eq!(buf.as_slice(), &[1, 2, 3, 4]); + let b: &[_] = &[1, 2, 3, 4]; + assert_eq!(buf.as_slice(), b); assert_eq!(reader.read(buf), Ok(3)); - assert_eq!(buf.slice(0, 3), &[5, 6, 7]); + let b: &[_] = &[5, 6, 7]; + assert_eq!(buf.slice(0, 3), b); assert!(reader.read(buf).is_err()); let mut reader = BufReader::new(in_buf.as_slice()); assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3)); @@ -537,13 +546,16 @@ mod test { let mut r = MemReader::new(vec![1, 2, 3, 4, 5, 6, 7, 8]); let mut buf = [0, ..3]; assert!(r.read_at_least(buf.len(), buf).is_ok()); - assert_eq!(buf.as_slice(), &[1, 2, 3]); + let b: &[_] = &[1, 2, 3]; + assert_eq!(buf.as_slice(), b); assert!(r.read_at_least(0, buf.mut_slice_to(0)).is_ok()); - assert_eq!(buf.as_slice(), &[1, 2, 3]); + assert_eq!(buf.as_slice(), b); assert!(r.read_at_least(buf.len(), buf).is_ok()); - assert_eq!(buf.as_slice(), &[4, 5, 6]); + let b: &[_] = &[4, 5, 6]; + assert_eq!(buf.as_slice(), b); assert!(r.read_at_least(buf.len(), buf).is_err()); - assert_eq!(buf.as_slice(), &[7, 8, 6]); + let b: &[_] = &[7, 8, 6]; + assert_eq!(buf.as_slice(), b); } fn do_bench_mem_writer(b: &mut Bencher, times: uint, len: uint) { diff --git a/src/libstd/io/result.rs b/src/libstd/io/result.rs index a69f6c10abf..03637079241 100644 --- a/src/libstd/io/result.rs +++ b/src/libstd/io/result.rs @@ -111,7 +111,8 @@ mod test { Ok(MemReader::new(vec!(0, 1, 2, 3))); let mut buf = [0, 0]; reader.read(buf).unwrap(); - assert_eq!(buf.as_slice(), &[0, 1]); + let b: &[_] = &[0, 1]; + assert_eq!(buf.as_slice(), b); } #[test] diff --git a/src/libstd/os.rs b/src/libstd/os.rs index ad666d70034..f452f8b23e7 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -295,7 +295,8 @@ pub fn env_as_bytes() -> Vec<(Vec,Vec)> { for p in input.iter() { let mut it = p.as_slice().splitn(1, |b| *b == b'='); let key = Vec::from_slice(it.next().unwrap()); - let val = Vec::from_slice(it.next().unwrap_or(&[])); + let default: &[u8] = &[]; + let val = Vec::from_slice(it.next().unwrap_or(default)); pairs.push((key, val)); } pairs diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 38d04324fe4..50441cb534d 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -846,7 +846,10 @@ impl<'a, P: GenericPath> Display<'a, P> { pub fn as_maybe_owned(&self) -> MaybeOwned<'a> { String::from_utf8_lossy(if self.filename { match self.path.filename() { - None => &[], + None => { + let result: &[u8] = &[]; + result + } Some(v) => v } } else { diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index b7bf75e39a5..b9b7a02b62f 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -531,7 +531,8 @@ mod test { r.shuffle(empty); let mut one = [1i]; r.shuffle(one); - assert_eq!(one.as_slice(), &[1]); + let b: &[_] = &[1]; + assert_eq!(one.as_slice(), b); let mut two = [1i, 2]; r.shuffle(two); @@ -539,7 +540,8 @@ mod test { let mut x = [1i, 1, 1]; r.shuffle(x); - assert_eq!(x.as_slice(), &[1, 1, 1]); + let b: &[_] = &[1, 1, 1]; + assert_eq!(x.as_slice(), b); } #[test] @@ -548,7 +550,8 @@ mod test { r.gen::(); let mut v = [1i, 1, 1]; r.shuffle(v); - assert_eq!(v.as_slice(), &[1, 1, 1]); + let b: &[_] = &[1, 1, 1]; + assert_eq!(v.as_slice(), b); assert_eq!(r.gen_range(0u, 1u), 0u); } diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index 5044d82a6ea..f68ace395aa 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -100,7 +100,8 @@ fn main() { let mut rand = Vec::with_capacity(n_keys); { - let mut rng: IsaacRng = SeedableRng::from_seed(&[1, 1, 1, 1, 1, 1, 1]); + let seed: &[_] = &[1, 1, 1, 1, 1, 1, 1]; + let mut rng: IsaacRng = SeedableRng::from_seed(seed); let mut set = HashSet::new(); while set.len() != n_keys { let next = rng.gen(); diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index 1d2d02d7d59..7f85bc1d700 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -164,7 +164,7 @@ fn main() { } }; - let seed = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let seed: &[_] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let max = 200000; { diff --git a/src/test/run-pass/byte-literals.rs b/src/test/run-pass/byte-literals.rs index 7fd7e3dbf00..058dc426766 100644 --- a/src/test/run-pass/byte-literals.rs +++ b/src/test/run-pass/byte-literals.rs @@ -37,13 +37,16 @@ pub fn main() { _ => fail!() } - assert_eq!(b"a\n\r\t\\\'\"\0\xF0", - &[97u8, 10u8, 13u8, 9u8, 92u8, 39u8, 34u8, 0u8, 240u8]); + let expected: &[_] = &[97u8, 10u8, 13u8, 9u8, 92u8, 39u8, 34u8, 0u8, 240u8]; + assert_eq!(b"a\n\r\t\\\'\"\0\xF0", expected); + let expected: &[_] = &[97u8, 98u8]; assert_eq!(b"a\ - b", &[97u8, 98u8]); - assert_eq!(BAR, &[97u8, 240u8, 9u8]); + b", expected); + let expected: &[_] = &[97u8, 240u8, 9u8]; + assert_eq!(BAR, expected); - match &[97u8, 10u8] { + let val: &[_] = &[97u8, 10u8]; + match val { b"a\n" => {}, _ => fail!(), } @@ -55,9 +58,12 @@ pub fn main() { _ => 3u }, 2); - assert_eq!(BAZ, &[97u8, 92u8, 110u8]); - assert_eq!(br"a\n", &[97u8, 92u8, 110u8]); + let expected: &[_] = &[97u8, 92u8, 110u8]; + assert_eq!(BAZ, expected); + let expected: &[_] = &[97u8, 92u8, 110u8]; + assert_eq!(br"a\n", expected); assert_eq!(br"a\n", b"a\\n"); - assert_eq!(br###"a"##b"###, &[97u8, 34u8, 35u8, 35u8, 98u8]); + let expected: &[_] = &[97u8, 34u8, 35u8, 35u8, 98u8]; + assert_eq!(br###"a"##b"###, expected); assert_eq!(br###"a"##b"###, b"a\"##b"); } diff --git a/src/test/run-pass/running-with-no-runtime.rs b/src/test/run-pass/running-with-no-runtime.rs index 44435dc2398..3f559df4b7e 100644 --- a/src/test/run-pass/running-with-no-runtime.rs +++ b/src/test/run-pass/running-with-no-runtime.rs @@ -43,14 +43,22 @@ fn main() { let args = os::args(); let me = args.get(0).as_slice(); - pass(Command::new(me).arg(&[1u8]).output().unwrap()); - pass(Command::new(me).arg(&[2u8]).output().unwrap()); - pass(Command::new(me).arg(&[3u8]).output().unwrap()); - pass(Command::new(me).arg(&[4u8]).output().unwrap()); - pass(Command::new(me).arg(&[5u8]).output().unwrap()); - pass(Command::new(me).arg(&[6u8]).output().unwrap()); - pass(Command::new(me).arg(&[7u8]).output().unwrap()); - pass(Command::new(me).arg(&[8u8]).output().unwrap()); + let x: &[u8] = &[1u8]; + pass(Command::new(me).arg(x).output().unwrap()); + let x: &[u8] = &[2u8]; + pass(Command::new(me).arg(x).output().unwrap()); + let x: &[u8] = &[3u8]; + pass(Command::new(me).arg(x).output().unwrap()); + let x: &[u8] = &[4u8]; + pass(Command::new(me).arg(x).output().unwrap()); + let x: &[u8] = &[5u8]; + pass(Command::new(me).arg(x).output().unwrap()); + let x: &[u8] = &[6u8]; + pass(Command::new(me).arg(x).output().unwrap()); + let x: &[u8] = &[7u8]; + pass(Command::new(me).arg(x).output().unwrap()); + let x: &[u8] = &[8u8]; + pass(Command::new(me).arg(x).output().unwrap()); } fn pass(output: ProcessOutput) { diff --git a/src/test/run-pass/syntax-extension-bytes.rs b/src/test/run-pass/syntax-extension-bytes.rs index 5b66d5f28a9..8d5333e5b3f 100644 --- a/src/test/run-pass/syntax-extension-bytes.rs +++ b/src/test/run-pass/syntax-extension-bytes.rs @@ -12,13 +12,17 @@ static static_vec: &'static [u8] = bytes!("abc", 0xFF, '!'); pub fn main() { let vec = bytes!("abc"); - assert_eq!(vec, &[97_u8, 98_u8, 99_u8]); + let expected: &[u8] = &[97_u8, 98_u8, 99_u8]; + assert_eq!(vec, expected); let vec = bytes!("null", 0); - assert_eq!(vec, &[110_u8, 117_u8, 108_u8, 108_u8, 0_u8]); + let expected: &[u8] = &[110_u8, 117_u8, 108_u8, 108_u8, 0_u8]; + assert_eq!(vec, expected); let vec = bytes!(' ', " ", 32, 32u8); - assert_eq!(vec, &[32_u8, 32_u8, 32_u8, 32_u8]); + let expected: &[u8] = &[32_u8, 32_u8, 32_u8, 32_u8]; + assert_eq!(vec, expected); - assert_eq!(static_vec, &[97_u8, 98_u8, 99_u8, 255_u8, 33_u8]); + let expected: &[u8] = &[97_u8, 98_u8, 99_u8, 255_u8, 33_u8]; + assert_eq!(static_vec, expected); } diff --git a/src/test/run-pass/typeck_type_placeholder_1.rs b/src/test/run-pass/typeck_type_placeholder_1.rs index f95e9ad7d83..10c91274f10 100644 --- a/src/test/run-pass/typeck_type_placeholder_1.rs +++ b/src/test/run-pass/typeck_type_placeholder_1.rs @@ -15,10 +15,11 @@ static CONSTEXPR: *const int = &413 as *const _; pub fn main() { let x: Vec<_> = range(0u, 5).collect(); - assert_eq!(x.as_slice(), &[0u,1,2,3,4]); + let expected: &[uint] = &[0,1,2,3,4]; + assert_eq!(x.as_slice(), expected); let x = range(0u, 5).collect::>(); - assert_eq!(x.as_slice(), &[0u,1,2,3,4]); + assert_eq!(x.as_slice(), expected); let y: _ = "hello"; assert_eq!(y.len(), 5); diff --git a/src/test/run-pass/vec-matching-legal-tail-element-borrow.rs b/src/test/run-pass/vec-matching-legal-tail-element-borrow.rs index c070e5dab77..2fd8a4ab256 100644 --- a/src/test/run-pass/vec-matching-legal-tail-element-borrow.rs +++ b/src/test/run-pass/vec-matching-legal-tail-element-borrow.rs @@ -10,6 +10,7 @@ pub fn main() { let x = &[1i, 2, 3, 4, 5]; + let x: &[int] = &[1, 2, 3, 4, 5]; if !x.is_empty() { let el = match x { [1, ..ref tail] => &tail[0], diff --git a/src/test/run-pass/vec-matching.rs b/src/test/run-pass/vec-matching.rs index 8ba8ba4482e..76f3b7bc280 100644 --- a/src/test/run-pass/vec-matching.rs +++ b/src/test/run-pass/vec-matching.rs @@ -23,12 +23,14 @@ fn b() { [a, b, ..c] => { assert_eq!(a, 1); assert_eq!(b, 2); - assert_eq!(c, &[3]); + let expected: &[_] = &[3]; + assert_eq!(c, expected); } } match x { [..a, b, c] => { - assert_eq!(a, &[1]); + let expected: &[_] = &[1]; + assert_eq!(a, expected); assert_eq!(b, 2); assert_eq!(c, 3); } @@ -36,7 +38,8 @@ fn b() { match x { [a, ..b, c] => { assert_eq!(a, 1); - assert_eq!(b, &[2]); + let expected: &[_] = &[2]; + assert_eq!(b, expected); assert_eq!(c, 3); } } diff --git a/src/test/run-pass/vec-to_str.rs b/src/test/run-pass/vec-to_str.rs index deb08a4608c..b96761f8b64 100644 --- a/src/test/run-pass/vec-to_str.rs +++ b/src/test/run-pass/vec-to_str.rs @@ -9,11 +9,10 @@ // except according to those terms. pub fn main() { - assert_eq!((vec!(0i, 1)).to_string(), "[0, 1]".to_string()); - assert_eq!((&[1i, 2]).to_string(), "[1, 2]".to_string()); + assert_eq!((vec!(0, 1)).to_string(), "[0, 1]".to_string()); - let foo = vec!(3i, 4); - let bar = &[4i, 5]; + let foo = vec!(3, 4); + let bar: &[int] = &[4, 5]; assert_eq!(foo.to_string(), "[3, 4]".to_string()); assert_eq!(bar.to_string(), "[4, 5]".to_string());