diff options
| author | Jorge Aparicio <japaricious@gmail.com> | 2015-02-01 21:53:25 -0500 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2015-02-05 13:45:01 -0500 |
| commit | 17bc7d8d5be3be9674d702ccad2fa88c487d23b0 (patch) | |
| tree | 325defba0f55b48273cd3f0814fe6c083dee5d41 /src/libstd/sys | |
| parent | 2c05354211b04a52cc66a0b8ad8b2225eaf9e972 (diff) | |
| download | rust-17bc7d8d5be3be9674d702ccad2fa88c487d23b0.tar.gz rust-17bc7d8d5be3be9674d702ccad2fa88c487d23b0.zip | |
cleanup: replace `as[_mut]_slice()` calls with deref coercions
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/common/thread_info.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/common/wtf8.rs | 110 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os_str.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/process.rs | 9 | ||||
| -rw-r--r-- | src/libstd/sys/windows/tty.rs | 2 |
5 files changed, 62 insertions, 63 deletions
diff --git a/src/libstd/sys/common/thread_info.rs b/src/libstd/sys/common/thread_info.rs index 7c9758ca924..ce67a584a0a 100644 --- a/src/libstd/sys/common/thread_info.rs +++ b/src/libstd/sys/common/thread_info.rs @@ -57,7 +57,7 @@ pub fn stack_guard() -> uint { pub fn set(stack_bounds: (uint, uint), stack_guard: uint, thread: Thread) { THREAD_INFO.with(|c| assert!(c.borrow().is_none())); match thread.name() { - Some(name) => unsafe { ::sys::thread::set_name(name.as_slice()); }, + Some(name) => unsafe { ::sys::thread::set_name(name); }, None => {} } THREAD_INFO.with(move |c| *c.borrow_mut() = Some(ThreadInfo{ diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index b30af10986b..04cba804e8d 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -140,7 +140,7 @@ impl ops::Deref for Wtf8Buf { impl fmt::Debug for Wtf8Buf { #[inline] fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { - self.as_slice().fmt(formatter) + fmt::Debug::fmt(&**self, formatter) } } @@ -220,7 +220,7 @@ impl Wtf8Buf { #[inline] pub fn as_slice(&self) -> &Wtf8 { - unsafe { mem::transmute(self.bytes.as_slice()) } + unsafe { mem::transmute(&*self.bytes) } } /// Reserves capacity for at least `additional` more bytes to be inserted @@ -309,7 +309,7 @@ impl Wtf8Buf { /// or if `new_len` is not a code point boundary. #[inline] pub fn truncate(&mut self, new_len: uint) { - assert!(is_code_point_boundary(self.as_slice(), new_len)); + assert!(is_code_point_boundary(self, new_len)); self.bytes.truncate(new_len) } @@ -771,7 +771,7 @@ impl<'a> Iterator for EncodeWide<'a> { let mut buf = [0u16; 2]; self.code_points.next().map(|code_point| { - let n = encode_utf16_raw(code_point.value, buf.as_mut_slice()) + let n = encode_utf16_raw(code_point.value, &mut buf) .unwrap_or(0); if n == 2 { self.extra = buf[1]; } buf[0] @@ -798,7 +798,7 @@ impl<S: Writer + Hasher> Hash<S> for CodePoint { impl<S: Writer + Hasher> Hash<S> for Wtf8Buf { #[inline] fn hash(&self, state: &mut S) { - state.write(self.bytes.as_slice()); + state.write(&self.bytes); 0xfeu8.hash(state) } } @@ -843,8 +843,8 @@ mod tests { #[test] fn code_point_to_string() { - assert_eq!(format!("{:?}", CodePoint::from_char('a')).as_slice(), "U+0061"); - assert_eq!(format!("{:?}", CodePoint::from_char('💩')).as_slice(), "U+1F4A9"); + assert_eq!(format!("{:?}", CodePoint::from_char('a')), "U+0061"); + assert_eq!(format!("{:?}", CodePoint::from_char('💩')), "U+1F4A9"); } #[test] @@ -865,142 +865,142 @@ mod tests { #[test] fn wtf8buf_new() { - assert_eq!(Wtf8Buf::new().bytes.as_slice(), b""); + assert_eq!(Wtf8Buf::new().bytes, b""); } #[test] fn wtf8buf_from_str() { - assert_eq!(Wtf8Buf::from_str("").bytes.as_slice(), b""); - assert_eq!(Wtf8Buf::from_str("aé 💩").bytes.as_slice(), + assert_eq!(Wtf8Buf::from_str("").bytes, b""); + assert_eq!(Wtf8Buf::from_str("aé 💩").bytes, b"a\xC3\xA9 \xF0\x9F\x92\xA9"); } #[test] fn wtf8buf_from_string() { - assert_eq!(Wtf8Buf::from_string(String::from_str("")).bytes.as_slice(), b""); - assert_eq!(Wtf8Buf::from_string(String::from_str("aé 💩")).bytes.as_slice(), + assert_eq!(Wtf8Buf::from_string(String::from_str("")).bytes, b""); + assert_eq!(Wtf8Buf::from_string(String::from_str("aé 💩")).bytes, b"a\xC3\xA9 \xF0\x9F\x92\xA9"); } #[test] fn wtf8buf_from_wide() { - assert_eq!(Wtf8Buf::from_wide(&[]).bytes.as_slice(), b""); + assert_eq!(Wtf8Buf::from_wide(&[]).bytes, b""); assert_eq!(Wtf8Buf::from_wide( - &[0x61, 0xE9, 0x20, 0xD83D, 0xD83D, 0xDCA9]).bytes.as_slice(), + &[0x61, 0xE9, 0x20, 0xD83D, 0xD83D, 0xDCA9]).bytes, b"a\xC3\xA9 \xED\xA0\xBD\xF0\x9F\x92\xA9"); } #[test] fn wtf8buf_push_str() { let mut string = Wtf8Buf::new(); - assert_eq!(string.bytes.as_slice(), b""); + assert_eq!(string.bytes, b""); string.push_str("aé 💩"); - assert_eq!(string.bytes.as_slice(), b"a\xC3\xA9 \xF0\x9F\x92\xA9"); + assert_eq!(string.bytes, b"a\xC3\xA9 \xF0\x9F\x92\xA9"); } #[test] fn wtf8buf_push_char() { let mut string = Wtf8Buf::from_str("aé "); - assert_eq!(string.bytes.as_slice(), b"a\xC3\xA9 "); + assert_eq!(string.bytes, b"a\xC3\xA9 "); string.push_char('💩'); - assert_eq!(string.bytes.as_slice(), b"a\xC3\xA9 \xF0\x9F\x92\xA9"); + assert_eq!(string.bytes, b"a\xC3\xA9 \xF0\x9F\x92\xA9"); } #[test] fn wtf8buf_push() { let mut string = Wtf8Buf::from_str("aé "); - assert_eq!(string.bytes.as_slice(), b"a\xC3\xA9 "); + assert_eq!(string.bytes, b"a\xC3\xA9 "); string.push(CodePoint::from_char('💩')); - assert_eq!(string.bytes.as_slice(), b"a\xC3\xA9 \xF0\x9F\x92\xA9"); + assert_eq!(string.bytes, b"a\xC3\xA9 \xF0\x9F\x92\xA9"); fn c(value: u32) -> CodePoint { CodePoint::from_u32(value).unwrap() } let mut string = Wtf8Buf::new(); string.push(c(0xD83D)); // lead string.push(c(0xDCA9)); // trail - assert_eq!(string.bytes.as_slice(), b"\xF0\x9F\x92\xA9"); // Magic! + assert_eq!(string.bytes, b"\xF0\x9F\x92\xA9"); // Magic! let mut string = Wtf8Buf::new(); string.push(c(0xD83D)); // lead string.push(c(0x20)); // not surrogate string.push(c(0xDCA9)); // trail - assert_eq!(string.bytes.as_slice(), b"\xED\xA0\xBD \xED\xB2\xA9"); + assert_eq!(string.bytes, b"\xED\xA0\xBD \xED\xB2\xA9"); let mut string = Wtf8Buf::new(); string.push(c(0xD800)); // lead string.push(c(0xDBFF)); // lead - assert_eq!(string.bytes.as_slice(), b"\xED\xA0\x80\xED\xAF\xBF"); + assert_eq!(string.bytes, b"\xED\xA0\x80\xED\xAF\xBF"); let mut string = Wtf8Buf::new(); string.push(c(0xD800)); // lead string.push(c(0xE000)); // not surrogate - assert_eq!(string.bytes.as_slice(), b"\xED\xA0\x80\xEE\x80\x80"); + assert_eq!(string.bytes, b"\xED\xA0\x80\xEE\x80\x80"); let mut string = Wtf8Buf::new(); string.push(c(0xD7FF)); // not surrogate string.push(c(0xDC00)); // trail - assert_eq!(string.bytes.as_slice(), b"\xED\x9F\xBF\xED\xB0\x80"); + assert_eq!(string.bytes, b"\xED\x9F\xBF\xED\xB0\x80"); let mut string = Wtf8Buf::new(); string.push(c(0x61)); // not surrogate, < 3 bytes string.push(c(0xDC00)); // trail - assert_eq!(string.bytes.as_slice(), b"\x61\xED\xB0\x80"); + assert_eq!(string.bytes, b"\x61\xED\xB0\x80"); let mut string = Wtf8Buf::new(); string.push(c(0xDC00)); // trail - assert_eq!(string.bytes.as_slice(), b"\xED\xB0\x80"); + assert_eq!(string.bytes, b"\xED\xB0\x80"); } #[test] fn wtf8buf_push_wtf8() { let mut string = Wtf8Buf::from_str("aé"); - assert_eq!(string.bytes.as_slice(), b"a\xC3\xA9"); + assert_eq!(string.bytes, b"a\xC3\xA9"); string.push_wtf8(Wtf8::from_str(" 💩")); - assert_eq!(string.bytes.as_slice(), b"a\xC3\xA9 \xF0\x9F\x92\xA9"); + assert_eq!(string.bytes, b"a\xC3\xA9 \xF0\x9F\x92\xA9"); fn w(value: &[u8]) -> &Wtf8 { unsafe { transmute(value) } } let mut string = Wtf8Buf::new(); string.push_wtf8(w(b"\xED\xA0\xBD")); // lead string.push_wtf8(w(b"\xED\xB2\xA9")); // trail - assert_eq!(string.bytes.as_slice(), b"\xF0\x9F\x92\xA9"); // Magic! + assert_eq!(string.bytes, b"\xF0\x9F\x92\xA9"); // Magic! let mut string = Wtf8Buf::new(); string.push_wtf8(w(b"\xED\xA0\xBD")); // lead string.push_wtf8(w(b" ")); // not surrogate string.push_wtf8(w(b"\xED\xB2\xA9")); // trail - assert_eq!(string.bytes.as_slice(), b"\xED\xA0\xBD \xED\xB2\xA9"); + assert_eq!(string.bytes, b"\xED\xA0\xBD \xED\xB2\xA9"); let mut string = Wtf8Buf::new(); string.push_wtf8(w(b"\xED\xA0\x80")); // lead string.push_wtf8(w(b"\xED\xAF\xBF")); // lead - assert_eq!(string.bytes.as_slice(), b"\xED\xA0\x80\xED\xAF\xBF"); + assert_eq!(string.bytes, b"\xED\xA0\x80\xED\xAF\xBF"); let mut string = Wtf8Buf::new(); string.push_wtf8(w(b"\xED\xA0\x80")); // lead string.push_wtf8(w(b"\xEE\x80\x80")); // not surrogate - assert_eq!(string.bytes.as_slice(), b"\xED\xA0\x80\xEE\x80\x80"); + assert_eq!(string.bytes, b"\xED\xA0\x80\xEE\x80\x80"); let mut string = Wtf8Buf::new(); string.push_wtf8(w(b"\xED\x9F\xBF")); // not surrogate string.push_wtf8(w(b"\xED\xB0\x80")); // trail - assert_eq!(string.bytes.as_slice(), b"\xED\x9F\xBF\xED\xB0\x80"); + assert_eq!(string.bytes, b"\xED\x9F\xBF\xED\xB0\x80"); let mut string = Wtf8Buf::new(); string.push_wtf8(w(b"a")); // not surrogate, < 3 bytes string.push_wtf8(w(b"\xED\xB0\x80")); // trail - assert_eq!(string.bytes.as_slice(), b"\x61\xED\xB0\x80"); + assert_eq!(string.bytes, b"\x61\xED\xB0\x80"); let mut string = Wtf8Buf::new(); string.push_wtf8(w(b"\xED\xB0\x80")); // trail - assert_eq!(string.bytes.as_slice(), b"\xED\xB0\x80"); + assert_eq!(string.bytes, b"\xED\xB0\x80"); } #[test] fn wtf8buf_truncate() { let mut string = Wtf8Buf::from_str("aé"); string.truncate(1); - assert_eq!(string.bytes.as_slice(), b"a"); + assert_eq!(string.bytes, b"a"); } #[test] @@ -1038,15 +1038,15 @@ mod tests { fn f(values: &[u32]) -> Wtf8Buf { values.iter().map(|&c| CodePoint::from_u32(c).unwrap()).collect::<Wtf8Buf>() }; - assert_eq!(f(&[0x61, 0xE9, 0x20, 0x1F4A9]).bytes.as_slice(), b"a\xC3\xA9 \xF0\x9F\x92\xA9"); + assert_eq!(f(&[0x61, 0xE9, 0x20, 0x1F4A9]).bytes, b"a\xC3\xA9 \xF0\x9F\x92\xA9"); - assert_eq!(f(&[0xD83D, 0xDCA9]).bytes.as_slice(), b"\xF0\x9F\x92\xA9"); // Magic! - assert_eq!(f(&[0xD83D, 0x20, 0xDCA9]).bytes.as_slice(), b"\xED\xA0\xBD \xED\xB2\xA9"); - assert_eq!(f(&[0xD800, 0xDBFF]).bytes.as_slice(), b"\xED\xA0\x80\xED\xAF\xBF"); - assert_eq!(f(&[0xD800, 0xE000]).bytes.as_slice(), b"\xED\xA0\x80\xEE\x80\x80"); - assert_eq!(f(&[0xD7FF, 0xDC00]).bytes.as_slice(), b"\xED\x9F\xBF\xED\xB0\x80"); - assert_eq!(f(&[0x61, 0xDC00]).bytes.as_slice(), b"\x61\xED\xB0\x80"); - assert_eq!(f(&[0xDC00]).bytes.as_slice(), b"\xED\xB0\x80"); + assert_eq!(f(&[0xD83D, 0xDCA9]).bytes, b"\xF0\x9F\x92\xA9"); // Magic! + assert_eq!(f(&[0xD83D, 0x20, 0xDCA9]).bytes, b"\xED\xA0\xBD \xED\xB2\xA9"); + assert_eq!(f(&[0xD800, 0xDBFF]).bytes, b"\xED\xA0\x80\xED\xAF\xBF"); + assert_eq!(f(&[0xD800, 0xE000]).bytes, b"\xED\xA0\x80\xEE\x80\x80"); + assert_eq!(f(&[0xD7FF, 0xDC00]).bytes, b"\xED\x9F\xBF\xED\xB0\x80"); + assert_eq!(f(&[0x61, 0xDC00]).bytes, b"\x61\xED\xB0\x80"); + assert_eq!(f(&[0xDC00]).bytes, b"\xED\xB0\x80"); } #[test] @@ -1058,23 +1058,23 @@ mod tests { string }; - assert_eq!(e(&[0x61, 0xE9], &[0x20, 0x1F4A9]).bytes.as_slice(), + assert_eq!(e(&[0x61, 0xE9], &[0x20, 0x1F4A9]).bytes, b"a\xC3\xA9 \xF0\x9F\x92\xA9"); - assert_eq!(e(&[0xD83D], &[0xDCA9]).bytes.as_slice(), b"\xF0\x9F\x92\xA9"); // Magic! - assert_eq!(e(&[0xD83D, 0x20], &[0xDCA9]).bytes.as_slice(), b"\xED\xA0\xBD \xED\xB2\xA9"); - assert_eq!(e(&[0xD800], &[0xDBFF]).bytes.as_slice(), b"\xED\xA0\x80\xED\xAF\xBF"); - assert_eq!(e(&[0xD800], &[0xE000]).bytes.as_slice(), b"\xED\xA0\x80\xEE\x80\x80"); - assert_eq!(e(&[0xD7FF], &[0xDC00]).bytes.as_slice(), b"\xED\x9F\xBF\xED\xB0\x80"); - assert_eq!(e(&[0x61], &[0xDC00]).bytes.as_slice(), b"\x61\xED\xB0\x80"); - assert_eq!(e(&[], &[0xDC00]).bytes.as_slice(), b"\xED\xB0\x80"); + assert_eq!(e(&[0xD83D], &[0xDCA9]).bytes, b"\xF0\x9F\x92\xA9"); // Magic! + assert_eq!(e(&[0xD83D, 0x20], &[0xDCA9]).bytes, b"\xED\xA0\xBD \xED\xB2\xA9"); + assert_eq!(e(&[0xD800], &[0xDBFF]).bytes, b"\xED\xA0\x80\xED\xAF\xBF"); + assert_eq!(e(&[0xD800], &[0xE000]).bytes, b"\xED\xA0\x80\xEE\x80\x80"); + assert_eq!(e(&[0xD7FF], &[0xDC00]).bytes, b"\xED\x9F\xBF\xED\xB0\x80"); + assert_eq!(e(&[0x61], &[0xDC00]).bytes, b"\x61\xED\xB0\x80"); + assert_eq!(e(&[], &[0xDC00]).bytes, b"\xED\xB0\x80"); } #[test] fn wtf8buf_show() { let mut string = Wtf8Buf::from_str("aé 💩"); string.push(CodePoint::from_u32(0xD800).unwrap()); - assert_eq!(format!("{:?}", string).as_slice(), r#""aé 💩\u{D800}""#); + assert_eq!(format!("{:?}", string), r#""aé 💩\u{D800}""#); } #[test] @@ -1086,7 +1086,7 @@ mod tests { fn wtf8_show() { let mut string = Wtf8Buf::from_str("aé 💩"); string.push(CodePoint::from_u32(0xD800).unwrap()); - assert_eq!(format!("{:?}", string.as_slice()).as_slice(), r#""aé 💩\u{D800}""#); + assert_eq!(format!("{:?}", string), r#""aé 💩\u{D800}""#); } #[test] diff --git a/src/libstd/sys/unix/os_str.rs b/src/libstd/sys/unix/os_str.rs index a2c93dea6a4..023d951dc4f 100644 --- a/src/libstd/sys/unix/os_str.rs +++ b/src/libstd/sys/unix/os_str.rs @@ -51,7 +51,7 @@ impl Buf { } pub fn as_slice(&self) -> &Slice { - unsafe { mem::transmute(self.inner.as_slice()) } + unsafe { mem::transmute(&*self.inner) } } pub fn into_string(self) -> Result<String, Buf> { diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 839263f1f17..eab60047aa2 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -389,7 +389,7 @@ fn make_command_line(prog: &CString, args: &[CString]) -> String { } let argvec: Vec<char> = arg.chars().collect(); for i in 0u..argvec.len() { - append_char_at(cmd, argvec.as_slice(), i); + append_char_at(cmd, &argvec, i); } if quote { cmd.push('"'); @@ -485,10 +485,9 @@ mod tests { fn test_make_command_line() { fn test_wrapper(prog: &str, args: &[&str]) -> String { make_command_line(&CString::from_slice(prog.as_bytes()), - args.iter() - .map(|a| CString::from_slice(a.as_bytes())) - .collect::<Vec<CString>>() - .as_slice()) + &args.iter() + .map(|a| CString::from_slice(a.as_bytes())) + .collect::<Vec<CString>>()) } assert_eq!( diff --git a/src/libstd/sys/windows/tty.rs b/src/libstd/sys/windows/tty.rs index f02c8e49f41..8a8b5309057 100644 --- a/src/libstd/sys/windows/tty.rs +++ b/src/libstd/sys/windows/tty.rs @@ -104,7 +104,7 @@ impl TTY { _ => (), }; utf16.truncate(num as uint); - let utf8 = match String::from_utf16(utf16.as_slice()) { + let utf8 = match String::from_utf16(&utf16) { Ok(utf8) => utf8.into_bytes(), Err(..) => return Err(invalid_encoding()), }; |
