about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-03-14 08:55:31 +0000
committerbors <bors@rust-lang.org>2015-03-14 08:55:31 +0000
commit766a4e1acc06061a30cf456840a9915526fb681e (patch)
tree16d2c602028d25d21f28b2d28b69a334e7c849d3 /src/libstd/sys
parentf7453f940b6cbc2b07a2c0d7612a11fa435aad95 (diff)
parent85080fa81d3ae6770eb228a982670746e55bf4d9 (diff)
downloadrust-766a4e1acc06061a30cf456840a9915526fb681e.tar.gz
rust-766a4e1acc06061a30cf456840a9915526fb681e.zip
Auto merge of #23333 - oli-obk:slice_from_raw_parts, r=alexcrichton
at least that's what the docs say: http://doc.rust-lang.org/std/slice/fn.from_raw_parts.html

A few situations got prettier. In some situations the mutability of the resulting and source pointers differed (and was cast away by transmute), the mutability matches now.
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/common/wtf8.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs
index 6c17f9910ac..4c0b26f8649 100644
--- a/src/libstd/sys/common/wtf8.rs
+++ b/src/libstd/sys/common/wtf8.rs
@@ -29,7 +29,6 @@ use core::prelude::*;
 
 use core::char::{encode_utf8_raw, encode_utf16_raw};
 use core::str::{char_range_at_raw, next_code_point};
-use core::raw::Slice as RawSlice;
 
 use ascii::*;
 use borrow::Cow;
@@ -214,10 +213,10 @@ impl Wtf8Buf {
         unsafe {
             // Attempt to not use an intermediate buffer by just pushing bytes
             // directly onto this string.
-            let slice = RawSlice {
-                data: self.bytes.as_ptr().offset(cur_len as int),
-                len: 4,
-            };
+            let slice = slice::from_raw_parts_mut(
+                self.bytes.as_mut_ptr().offset(cur_len as int),
+                4
+            );
             let used = encode_utf8_raw(code_point.value, mem::transmute(slice))
                 .unwrap_or(0);
             self.bytes.set_len(cur_len + used);
@@ -725,10 +724,11 @@ pub fn is_code_point_boundary(slice: &Wtf8, index: uint) -> bool {
 /// Copied from core::str::raw::slice_unchecked
 #[inline]
 pub unsafe fn slice_unchecked(s: &Wtf8, begin: uint, end: uint) -> &Wtf8 {
-    mem::transmute(RawSlice {
-        data: s.bytes.as_ptr().offset(begin as int),
-        len: end - begin,
-    })
+    // memory layout of an &[u8] and &Wtf8 are the same
+    mem::transmute(slice::from_raw_parts(
+        s.bytes.as_ptr().offset(begin as int),
+        end - begin
+    ))
 }
 
 /// Copied from core::str::raw::slice_error_fail