Rollup merge of #21926 - mzabaluev:raw-lifetime, r=alexcrichton

New functions, `slice::from_raw_parts` and `slice::from_raw_parts_mut`,
are added to implement the lifetime convention as agreed in rust-lang/rfcs#556.
The functions `slice::from_raw_buf` and `slice::from_raw_mut_buf` are
left deprecated for the time being.

Holding back on changing the signature of `std::ffi::c_str_to_bytes` as consensus in rust-lang/rfcs#592 is building to replace it with a composition of other functions.

Contribution to #21923.
This commit is contained in:
Manish Goregaokar
2015-02-06 05:40:52 +05:30
10 changed files with 82 additions and 32 deletions

View File

@@ -24,7 +24,6 @@ use error::Error as StdError;
use fmt;
use iter::Iterator;
use marker::Sized;
use mem;
use ops::{Drop, FnOnce};
use option::Option::{self, Some, None};
use ptr::PtrExt;
@@ -69,8 +68,8 @@ fn with_end_to_cap<F>(v: &mut Vec<u8>, f: F) -> Result<usize>
unsafe {
let n = try!(f({
let base = v.as_mut_ptr().offset(v.len() as isize);
black_box(slice::from_raw_mut_buf(mem::copy_lifetime(v, &base),
v.capacity() - v.len()))
black_box(slice::from_raw_parts_mut(base,
v.capacity() - v.len()))
}));
// If the closure (typically a `read` implementation) reported that it