Skip to content

Commit e933ee6

Browse files
committed
Make some slice coercions explicit - part 2
1 parent 0e2f9b9 commit e933ee6

File tree

34 files changed

+215
-215
lines changed

34 files changed

+215
-215
lines changed

src/libcollections/string.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ impl String {
246246
/// // 𝄞music
247247
/// let mut v = [0xD834, 0xDD1E, 0x006d, 0x0075,
248248
/// 0x0073, 0x0069, 0x0063];
249-
/// assert_eq!(String::from_utf16(v), Some("𝄞music".to_string()));
249+
/// assert_eq!(String::from_utf16(&v), Some("𝄞music".to_string()));
250250
///
251251
/// // 𝄞mu<invalid>ic
252252
/// v[4] = 0xD800;
253-
/// assert_eq!(String::from_utf16(v), None);
253+
/// assert_eq!(String::from_utf16(&v), None);
254254
/// ```
255255
#[unstable = "error value in return may change"]
256256
pub fn from_utf16(v: &[u16]) -> Option<String> {
@@ -274,7 +274,7 @@ impl String {
274274
/// 0x0073, 0xDD1E, 0x0069, 0x0063,
275275
/// 0xD834];
276276
///
277-
/// assert_eq!(String::from_utf16_lossy(v),
277+
/// assert_eq!(String::from_utf16_lossy(&v),
278278
/// "𝄞mus\uFFFDic\uFFFD".to_string());
279279
/// ```
280280
#[stable]
@@ -288,7 +288,7 @@ impl String {
288288
///
289289
/// ```rust
290290
/// let chars = ['h', 'e', 'l', 'l', 'o'];
291-
/// let s = String::from_chars(chars);
291+
/// let s = String::from_chars(&chars);
292292
/// assert_eq!(s.as_slice(), "hello");
293293
/// ```
294294
#[inline]
@@ -592,7 +592,7 @@ impl String {
592592
assert!(self.as_slice().is_char_boundary(idx));
593593
self.vec.reserve_additional(4);
594594
let mut bits = [0, ..4];
595-
let amt = ch.encode_utf8(bits).unwrap();
595+
let amt = ch.encode_utf8(&mut bits).unwrap();
596596

597597
unsafe {
598598
ptr::copy_memory(self.vec.as_mut_ptr().offset((idx + amt) as int),
@@ -981,30 +981,30 @@ mod tests {
981981
fn test_utf16_invalid() {
982982
// completely positive cases tested above.
983983
// lead + eof
984-
assert_eq!(String::from_utf16([0xD800]), None);
984+
assert_eq!(String::from_utf16(&[0xD800]), None);
985985
// lead + lead
986-
assert_eq!(String::from_utf16([0xD800, 0xD800]), None);
986+
assert_eq!(String::from_utf16(&[0xD800, 0xD800]), None);
987987

988988
// isolated trail
989-
assert_eq!(String::from_utf16([0x0061, 0xDC00]), None);
989+
assert_eq!(String::from_utf16(&[0x0061, 0xDC00]), None);
990990

991991
// general
992-
assert_eq!(String::from_utf16([0xD800, 0xd801, 0xdc8b, 0xD800]), None);
992+
assert_eq!(String::from_utf16(&[0xD800, 0xd801, 0xdc8b, 0xD800]), None);
993993
}
994994

995995
#[test]
996996
fn test_from_utf16_lossy() {
997997
// completely positive cases tested above.
998998
// lead + eof
999-
assert_eq!(String::from_utf16_lossy([0xD800]), String::from_str("\uFFFD"));
999+
assert_eq!(String::from_utf16_lossy(&[0xD800]), String::from_str("\uFFFD"));
10001000
// lead + lead
1001-
assert_eq!(String::from_utf16_lossy([0xD800, 0xD800]), String::from_str("\uFFFD\uFFFD"));
1001+
assert_eq!(String::from_utf16_lossy(&[0xD800, 0xD800]), String::from_str("\uFFFD\uFFFD"));
10021002

10031003
// isolated trail
1004-
assert_eq!(String::from_utf16_lossy([0x0061, 0xDC00]), String::from_str("a\uFFFD"));
1004+
assert_eq!(String::from_utf16_lossy(&[0x0061, 0xDC00]), String::from_str("a\uFFFD"));
10051005

10061006
// general
1007-
assert_eq!(String::from_utf16_lossy([0xD800, 0xd801, 0xdc8b, 0xD800]),
1007+
assert_eq!(String::from_utf16_lossy(&[0xD800, 0xd801, 0xdc8b, 0xD800]),
10081008
String::from_str("\uFFFD𐒋\uFFFD"));
10091009
}
10101010

@@ -1031,7 +1031,7 @@ mod tests {
10311031
let mut s = String::from_str("ABC");
10321032
unsafe {
10331033
let mv = s.as_mut_vec();
1034-
mv.push_all([b'D']);
1034+
mv.push_all(&[b'D']);
10351035
}
10361036
assert_eq!(s.as_slice(), "ABCD");
10371037
}

src/libcollections/tree/set.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -840,14 +840,14 @@ mod test {
840840
check(a, b, expected, |x, y, f| x.intersection(y).all(f))
841841
}
842842

843-
check_intersection([], [], []);
844-
check_intersection([1, 2, 3], [], []);
845-
check_intersection([], [1, 2, 3], []);
846-
check_intersection([2], [1, 2, 3], [2]);
847-
check_intersection([1, 2, 3], [2], [2]);
848-
check_intersection([11, 1, 3, 77, 103, 5, -5],
849-
[2, 11, 77, -9, -42, 5, 3],
850-
[3, 5, 11, 77]);
843+
check_intersection(&[], &[], &[]);
844+
check_intersection(&[1, 2, 3], &[], &[]);
845+
check_intersection(&[], &[1, 2, 3], &[]);
846+
check_intersection(&[2], &[1, 2, 3], &[2]);
847+
check_intersection(&[1, 2, 3], &[2], &[2]);
848+
check_intersection(&[11, 1, 3, 77, 103, 5, -5],
849+
&[2, 11, 77, -9, -42, 5, 3],
850+
&[3, 5, 11, 77]);
851851
}
852852

853853
#[test]
@@ -856,15 +856,15 @@ mod test {
856856
check(a, b, expected, |x, y, f| x.difference(y).all(f))
857857
}
858858

859-
check_difference([], [], []);
860-
check_difference([1, 12], [], [1, 12]);
861-
check_difference([], [1, 2, 3, 9], []);
862-
check_difference([1, 3, 5, 9, 11],
863-
[3, 9],
864-
[1, 5, 11]);
865-
check_difference([-5, 11, 22, 33, 40, 42],
866-
[-12, -5, 14, 23, 34, 38, 39, 50],
867-
[11, 22, 33, 40, 42]);
859+
check_difference(&[], &[], &[]);
860+
check_difference(&[1, 12], &[], &[1, 12]);
861+
check_difference(&[], &[1, 2, 3, 9], &[]);
862+
check_difference(&[1, 3, 5, 9, 11],
863+
&[3, 9],
864+
&[1, 5, 11]);
865+
check_difference(&[-5, 11, 22, 33, 40, 42],
866+
&[-12, -5, 14, 23, 34, 38, 39, 50],
867+
&[11, 22, 33, 40, 42]);
868868
}
869869

870870
#[test]
@@ -874,12 +874,12 @@ mod test {
874874
check(a, b, expected, |x, y, f| x.symmetric_difference(y).all(f))
875875
}
876876

877-
check_symmetric_difference([], [], []);
878-
check_symmetric_difference([1, 2, 3], [2], [1, 3]);
879-
check_symmetric_difference([2], [1, 2, 3], [1, 3]);
880-
check_symmetric_difference([1, 3, 5, 9, 11],
881-
[-2, 3, 9, 14, 22],
882-
[-2, 1, 5, 11, 14, 22]);
877+
check_symmetric_difference(&[], &[], &[]);
878+
check_symmetric_difference(&[1, 2, 3], &[2], &[1, 3]);
879+
check_symmetric_difference(&[2], &[1, 2, 3], &[1, 3]);
880+
check_symmetric_difference(&[1, 3, 5, 9, 11],
881+
&[-2, 3, 9, 14, 22],
882+
&[-2, 1, 5, 11, 14, 22]);
883883
}
884884

885885
#[test]
@@ -889,12 +889,12 @@ mod test {
889889
check(a, b, expected, |x, y, f| x.union(y).all(f))
890890
}
891891

892-
check_union([], [], []);
893-
check_union([1, 2, 3], [2], [1, 2, 3]);
894-
check_union([2], [1, 2, 3], [1, 2, 3]);
895-
check_union([1, 3, 5, 9, 11, 16, 19, 24],
896-
[-2, 1, 5, 9, 13, 19],
897-
[-2, 1, 3, 5, 9, 11, 13, 16, 19, 24]);
892+
check_union(&[], &[], &[]);
893+
check_union(&[1, 2, 3], &[2], &[1, 2, 3]);
894+
check_union(&[2], &[1, 2, 3], &[1, 2, 3]);
895+
check_union(&[1, 3, 5, 9, 11, 16, 19, 24],
896+
&[-2, 1, 5, 9, 13, 19],
897+
&[-2, 1, 3, 5, 9, 11, 13, 16, 19, 24]);
898898
}
899899

900900
#[test]

src/libcollections/vec.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use slice::{CloneableVector};
4747
/// vec[0] = 7i;
4848
/// assert_eq!(vec[0], 7);
4949
///
50-
/// vec.push_all([1, 2, 3]);
50+
/// vec.push_all(&[1, 2, 3]);
5151
///
5252
/// for x in vec.iter() {
5353
/// println!("{}", x);
@@ -306,7 +306,7 @@ impl<T: Clone> Vec<T> {
306306
///
307307
/// ```
308308
/// let mut vec = vec![1i];
309-
/// vec.push_all([2i, 3, 4]);
309+
/// vec.push_all(&[2i, 3, 4]);
310310
/// assert_eq!(vec, vec![1, 2, 3, 4]);
311311
/// ```
312312
#[inline]
@@ -643,7 +643,7 @@ impl<T> Vec<T> {
643643
///
644644
/// ```
645645
/// let mut vec: Vec<int> = Vec::with_capacity(10);
646-
/// vec.push_all([1, 2, 3]);
646+
/// vec.push_all(&[1, 2, 3]);
647647
/// assert_eq!(vec.capacity(), 10);
648648
/// vec.shrink_to_fit();
649649
/// assert!(vec.capacity() >= 3);
@@ -1680,7 +1680,7 @@ mod tests {
16801680
#[test]
16811681
fn test_as_vec() {
16821682
let xs = [1u8, 2u8, 3u8];
1683-
assert_eq!(as_vec(xs).as_slice(), xs.as_slice());
1683+
assert_eq!(as_vec(&xs).as_slice(), xs.as_slice());
16841684
}
16851685

16861686
#[test]
@@ -1770,27 +1770,27 @@ mod tests {
17701770
let mut values = vec![1u8,2,3,4,5];
17711771
{
17721772
let slice = values.slice_from_mut(2);
1773-
assert!(slice == [3, 4, 5]);
1773+
assert!(slice == &mut [3, 4, 5]);
17741774
for p in slice.iter_mut() {
17751775
*p += 2;
17761776
}
17771777
}
17781778

1779-
assert!(values.as_slice() == [1, 2, 5, 6, 7]);
1779+
assert!(values.as_slice() == &[1, 2, 5, 6, 7]);
17801780
}
17811781

17821782
#[test]
17831783
fn test_slice_to_mut() {
17841784
let mut values = vec![1u8,2,3,4,5];
17851785
{
17861786
let slice = values.slice_to_mut(2);
1787-
assert!(slice == [1, 2]);
1787+
assert!(slice == &mut [1, 2]);
17881788
for p in slice.iter_mut() {
17891789
*p += 1;
17901790
}
17911791
}
17921792

1793-
assert!(values.as_slice() == [2, 3, 3, 4, 5]);
1793+
assert!(values.as_slice() == &[2, 3, 3, 4, 5]);
17941794
}
17951795

17961796
#[test]

src/libcore/finally.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<T> Finally<T> for fn() -> T {
7979
*
8080
* struct State<'a> { buffer: &'a mut [u8], len: uint }
8181
* # let mut buf = [];
82-
* let mut state = State { buffer: buf, len: 0 };
82+
* let mut state = State { buffer: &mut buf, len: 0 };
8383
* try_finally(
8484
* &mut state, (),
8585
* |state, ()| {

src/libcore/fmt/float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
315315
}
316316
}
317317

318-
let mut filler = Filler { buf: buf, end: &mut end };
318+
let mut filler = Filler { buf: &mut buf, end: &mut end };
319319
match sign {
320320
SignNeg => {
321321
let _ = format_args!(|args| {

src/libcore/fmt/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl<'a> Formatter<'a> {
392392
let write_prefix = |f: &mut Formatter| {
393393
for c in sign.into_iter() {
394394
let mut b = [0, ..4];
395-
let n = c.encode_utf8(b).unwrap_or(0);
395+
let n = c.encode_utf8(&mut b).unwrap_or(0);
396396
try!(f.buf.write(b[..n]));
397397
}
398398
if prefixed { f.buf.write(prefix.as_bytes()) }
@@ -497,7 +497,7 @@ impl<'a> Formatter<'a> {
497497
};
498498

499499
let mut fill = [0u8, ..4];
500-
let len = self.fill.encode_utf8(fill).unwrap_or(0);
500+
let len = self.fill.encode_utf8(&mut fill).unwrap_or(0);
501501

502502
for _ in range(0, pre_pad) {
503503
try!(self.buf.write(fill[..len]));
@@ -586,7 +586,7 @@ impl Char for char {
586586
use char::Char;
587587

588588
let mut utf8 = [0u8, ..4];
589-
let amt = self.encode_utf8(utf8).unwrap_or(0);
589+
let amt = self.encode_utf8(&mut utf8).unwrap_or(0);
590590
let s: &str = unsafe { mem::transmute(utf8[..amt]) };
591591
String::fmt(s, f)
592592
}

src/libcore/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ extern "rust-intrinsic" {
228228
/// use std::mem;
229229
///
230230
/// let v: &[u8] = unsafe { mem::transmute("L") };
231-
/// assert!(v == [76u8]);
231+
/// assert!(v == &[76u8]);
232232
/// ```
233233
pub fn transmute<T,U>(e: T) -> U;
234234

src/libcore/option.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ impl<T> Option<T> {
264264
/// let mut x = Some("Diamonds");
265265
/// {
266266
/// let v = x.as_mut_slice();
267-
/// assert!(v == ["Diamonds"]);
267+
/// assert!(v == &mut ["Diamonds"]);
268268
/// v[0] = "Dirt";
269-
/// assert!(v == ["Dirt"]);
269+
/// assert!(v == &mut ["Dirt"]);
270270
/// }
271271
/// assert_eq!(x, Some("Dirt"));
272272
/// ```

src/libcore/result.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,14 @@ impl<T, E> Result<T, E> {
452452
/// let mut x: Result<&str, uint> = Ok("Gold");
453453
/// {
454454
/// let v = x.as_mut_slice();
455-
/// assert!(v == ["Gold"]);
455+
/// assert!(v == &mut ["Gold"]);
456456
/// v[0] = "Silver";
457-
/// assert!(v == ["Silver"]);
457+
/// assert!(v == &mut ["Silver"]);
458458
/// }
459459
/// assert_eq!(x, Ok("Silver"));
460460
///
461461
/// let mut x: Result<&str, uint> = Err(45);
462-
/// assert!(x.as_mut_slice() == []);
462+
/// assert!(x.as_mut_slice() == &mut []);
463463
/// ```
464464
#[inline]
465465
#[unstable = "waiting for mut conventions"]

src/libcore/slice.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ pub trait MutableSlice<T> for Sized? {
558558
/// ```rust
559559
/// let mut v = ["a", "b", "c", "d"];
560560
/// v.swap(1, 3);
561-
/// assert!(v == ["a", "d", "c", "b"]);
561+
/// assert!(v == &["a", "d", "c", "b"]);
562562
/// ```
563563
#[unstable = "waiting on final error conventions"]
564564
fn swap(&mut self, a: uint, b: uint);
@@ -605,7 +605,7 @@ pub trait MutableSlice<T> for Sized? {
605605
/// ```rust
606606
/// let mut v = [1i, 2, 3];
607607
/// v.reverse();
608-
/// assert!(v == [3i, 2, 1]);
608+
/// assert!(v == &[3i, 2, 1]);
609609
/// ```
610610
#[experimental = "may be moved to iterators instead"]
611611
fn reverse(&mut self);
@@ -867,12 +867,12 @@ pub trait MutableCloneableSlice<T> for Sized? {
867867
/// let mut dst = [0i, 0, 0];
868868
/// let src = [1i, 2];
869869
///
870-
/// assert!(dst.clone_from_slice(src) == 2);
871-
/// assert!(dst == [1, 2, 0]);
870+
/// assert!(dst.clone_from_slice(&src) == 2);
871+
/// assert!(dst == &[1, 2, 0]);
872872
///
873873
/// let src2 = [3i, 4, 5, 6];
874-
/// assert!(dst.clone_from_slice(src2) == 3);
875-
/// assert!(dst == [3i, 4, 5]);
874+
/// assert!(dst.clone_from_slice(&src2) == 3);
875+
/// assert!(dst == &[3i, 4, 5]);
876876
/// ```
877877
fn clone_from_slice(&mut self, &[T]) -> uint;
878878
}

src/libcore/str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ impl<'a> Iterator<Utf16Item> for Utf16Items<'a> {
974974
/// 0x0073, 0xDD1E, 0x0069, 0x0063,
975975
/// 0xD834];
976976
///
977-
/// assert_eq!(str::utf16_items(v).collect::<Vec<_>>(),
977+
/// assert_eq!(str::utf16_items(&v).collect::<Vec<_>>(),
978978
/// vec![ScalarValue('𝄞'),
979979
/// ScalarValue('m'), ScalarValue('u'), ScalarValue('s'),
980980
/// LoneSurrogate(0xDD1E),
@@ -996,12 +996,12 @@ pub fn utf16_items<'a>(v: &'a [u16]) -> Utf16Items<'a> {
996996
/// // "abcd"
997997
/// let mut v = ['a' as u16, 'b' as u16, 'c' as u16, 'd' as u16];
998998
/// // no NULs so no change
999-
/// assert_eq!(str::truncate_utf16_at_nul(v), v.as_slice());
999+
/// assert_eq!(str::truncate_utf16_at_nul(&v), v.as_slice());
10001000
///
10011001
/// // "ab\0d"
10021002
/// v[2] = 0;
10031003
/// let b: &[_] = &['a' as u16, 'b' as u16];
1004-
/// assert_eq!(str::truncate_utf16_at_nul(v), b);
1004+
/// assert_eq!(str::truncate_utf16_at_nul(&v), b);
10051005
/// ```
10061006
pub fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] {
10071007
match v.iter().position(|c| *c == 0) {

0 commit comments

Comments
 (0)