]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #23333 - oli-obk:slice_from_raw_parts, r=alexcrichton
authorbors <bors@rust-lang.org>
Sat, 14 Mar 2015 08:55:31 +0000 (08:55 +0000)
committerbors <bors@rust-lang.org>
Sat, 14 Mar 2015 08:55:31 +0000 (08:55 +0000)
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.

1  2 
src/librustc_llvm/lib.rs
src/libstd/old_io/mod.rs
src/libstd/sys/common/wtf8.rs

diff --combined src/librustc_llvm/lib.rs
index 71233ff5003933844898b8e860b380662b28e459,2c266c4cc5d0a19f3b42e26f3463dd78b360b29b..506bf4a058fc6f155e10b3b8a7a5ec4709c97d3f
  
  #![feature(box_syntax)]
  #![feature(collections)]
- #![feature(core)]
  #![feature(int_uint)]
  #![feature(libc)]
  #![feature(link_args)]
  #![feature(staged_api)]
 -#![feature(path)]
  #![cfg_attr(unix, feature(std_misc))]
  
  extern crate libc;
@@@ -58,7 -58,7 +57,7 @@@ pub use self::Linkage::*
  
  use std::ffi::CString;
  use std::cell::RefCell;
- use std::{raw, mem};
+ use std::{slice, mem};
  use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
  use libc::{c_longlong, c_ulonglong, c_void};
  use debuginfo::{DIBuilderRef, DIDescriptor,
@@@ -2226,10 -2226,7 +2225,7 @@@ type RustStringRepr = *mut RefCell<Vec<
  pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
                                                       ptr: *const c_char,
                                                       size: size_t) {
-     let slice: &[u8] = mem::transmute(raw::Slice {
-         data: ptr as *const u8,
-         len: size as uint,
-     });
+     let slice = slice::from_raw_parts(ptr as *const u8, size as uint);
  
      let sr: RustStringRepr = mem::transmute(sr);
      (*sr).borrow_mut().push_all(slice);
diff --combined src/libstd/old_io/mod.rs
index 9d438978f4211e67f5dd787689220f9e7ffea5d4,ce6e8e527af1b0e211c86f88c90e64ddb8fb42ba..332b941bcc0fbfa16c4d7e06c48834345cfdf153
  #![deny(unused_must_use)]
  #![allow(deprecated)] // seriously this is all deprecated
  #![allow(unused_imports)]
 +#![deprecated(since = "1.0.0",
 +              reasons = "APIs have been replaced with new I/O modules such as \
 +                         std::{io, fs, net, process}")]
  
  pub use self::SeekStyle::*;
  pub use self::FileMode::*;
@@@ -931,15 -928,15 +931,15 @@@ impl<'a> Reader for &'a mut (Reader+'a
  // Private function here because we aren't sure if we want to expose this as
  // API yet. If so, it should be a method on Vec.
  unsafe fn slice_vec_capacity<'a, T>(v: &'a mut Vec<T>, start: uint, end: uint) -> &'a mut [T] {
-     use raw::Slice;
+     use slice;
      use ptr::PtrExt;
  
      assert!(start <= end);
      assert!(end <= v.capacity());
-     transmute(Slice {
-         data: v.as_ptr().offset(start as int),
-         len: end - start
-     })
+     slice::from_raw_parts_mut(
+         v.as_mut_ptr().offset(start as int),
+         end - start
+     )
  }
  
  /// A `RefReader` is a struct implementing `Reader` which contains a reference
index 6c17f9910ac88367a005cda453836905e14a2376,991fe46eb29076a40e749d377865f7b134ce89da..4c0b26f8649d85afa5be4857fc5d36dc19c55023
  //! nor can it decode WTF-8 from arbitrary bytes.
  //! WTF-8 strings can be obtained from UTF-8, UTF-16, or code points.
  
 +// this module is imported from @SimonSapin's repo and has tons of dead code on
 +// unix (it's mostly used on windows), so don't worry about dead code here.
 +#![allow(dead_code)]
 +
  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 -209,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 -720,11 +724,11 @@@ pub fn is_code_point_boundary(slice: &W
  /// 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