auto merge of #19152 : alexcrichton/rust/issue-17863, r=aturon

This commit is an implementation of [RFC 240][rfc] when applied to the standard
library. It primarily deprecates the entirety of `string::raw`, `vec::raw`,
`slice::raw`, and `str::raw` in favor of associated functions, methods, and
other free functions. The detailed renaming is:

* slice::raw::buf_as_slice => slice::from_raw_buf
* slice::raw::mut_buf_as_slice => slice::from_raw_mut_buf
* slice::shift_ptr => deprecated with no replacement
* slice::pop_ptr => deprecated with no replacement
* str::raw::from_utf8 => str::from_utf8_unchecked
* str::raw::c_str_to_static_slice => str::from_c_str
* str::raw::slice_bytes => deprecated for slice_unchecked (slight semantic diff)
* str::raw::slice_unchecked => str.slice_unchecked
* string::raw::from_parts => String::from_raw_parts
* string::raw::from_buf_len => String::from_raw_buf_len
* string::raw::from_buf => String::from_raw_buf
* string::raw::from_utf8 => String::from_utf8_unchecked
* vec::raw::from_buf => Vec::from_raw_buf

All previous functions exist in their `#[deprecated]` form, and the deprecation
messages indicate how to migrate to the newer variants.

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0240-unsafe-api-location.md
[breaking-change]

Closes #17863
This commit is contained in:
bors 2014-11-23 05:46:52 +00:00
commit 641e2a110d
15 changed files with 304 additions and 208 deletions

View file

@ -248,7 +248,7 @@ pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> {
unsafe {
#[cfg(windows)]
unsafe fn get_env_pairs() -> Vec<Vec<u8>> {
use slice::raw;
use slice;
use libc::funcs::extra::kernel32::{
GetEnvironmentStringsW,
@ -281,9 +281,9 @@ pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> {
while *(p as *const _).offset(len) != 0 {
len += 1;
}
raw::buf_as_slice(p, len as uint, |s| {
result.push(String::from_utf16_lossy(s).into_bytes());
});
let p = p as *const u16;
let s = slice::from_raw_buf(&p, len as uint);
result.push(String::from_utf16_lossy(s).into_bytes());
i += len as int + 1;
}
FreeEnvironmentStringsW(ch);
@ -1071,9 +1071,9 @@ fn real_args() -> Vec<String> {
while *ptr.offset(len as int) != 0 { len += 1; }
// Push it onto the list.
let opt_s = slice::raw::buf_as_slice(ptr as *const _, len, |buf| {
String::from_utf16(::str::truncate_utf16_at_nul(buf))
});
let ptr = ptr as *const u16;
let buf = slice::from_raw_buf(&ptr, len);
let opt_s = String::from_utf16(::str::truncate_utf16_at_nul(buf));
opt_s.expect("CommandLineToArgvW returned invalid UTF-16")
});