Merge branch 'master' into frewsxcv-osstr
This commit is contained in:
commit
bc6eecd0c2
1
configure
vendored
1
configure
vendored
@ -445,6 +445,7 @@ opt dist-host-only 0 "only install bins for the host architecture"
|
||||
opt inject-std-version 1 "inject the current compiler version of libstd into programs"
|
||||
opt llvm-version-check 1 "check if the LLVM version is supported, build anyway"
|
||||
opt codegen-tests 1 "run the src/test/codegen tests"
|
||||
opt save-analysis 0 "save API analysis data"
|
||||
opt option-checking 1 "complain about unrecognized options in this configure script"
|
||||
opt ninja 0 "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)"
|
||||
opt locked-deps 0 "force Cargo.lock to be up to date"
|
||||
|
@ -74,6 +74,7 @@ pub struct Config {
|
||||
pub rustc_default_ar: Option<String>,
|
||||
pub rust_optimize_tests: bool,
|
||||
pub rust_debuginfo_tests: bool,
|
||||
pub rust_save_analysis: bool,
|
||||
pub rust_dist_src: bool,
|
||||
|
||||
pub build: String,
|
||||
@ -225,6 +226,7 @@ struct Rust {
|
||||
optimize_tests: Option<bool>,
|
||||
debuginfo_tests: Option<bool>,
|
||||
codegen_tests: Option<bool>,
|
||||
save_analysis: Option<bool>,
|
||||
}
|
||||
|
||||
/// TOML representation of how each build target is configured.
|
||||
@ -350,6 +352,7 @@ impl Config {
|
||||
set(&mut config.rust_optimize_tests, rust.optimize_tests);
|
||||
set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
|
||||
set(&mut config.codegen_tests, rust.codegen_tests);
|
||||
set(&mut config.rust_save_analysis, rust.save_analysis);
|
||||
set(&mut config.rust_rpath, rust.rpath);
|
||||
set(&mut config.debug_jemalloc, rust.debug_jemalloc);
|
||||
set(&mut config.use_jemalloc, rust.use_jemalloc);
|
||||
@ -457,6 +460,7 @@ impl Config {
|
||||
("LOCAL_REBUILD", self.local_rebuild),
|
||||
("NINJA", self.ninja),
|
||||
("CODEGEN_TESTS", self.codegen_tests),
|
||||
("SAVE_ANALYSIS", self.rust_save_analysis),
|
||||
("LOCKED_DEPS", self.locked_deps),
|
||||
("VENDOR", self.vendor),
|
||||
("FULL_BOOTSTRAP", self.full_bootstrap),
|
||||
|
@ -234,6 +234,9 @@
|
||||
# saying that the FileCheck executable is missing, you may want to disable this.
|
||||
#codegen-tests = true
|
||||
|
||||
# Flag indicating whether the API analysis data should be saved.
|
||||
#save-analysis = false
|
||||
|
||||
# =============================================================================
|
||||
# Options for specific targets
|
||||
#
|
||||
|
@ -311,18 +311,14 @@ pub fn rust_src_location(build: &Build) -> PathBuf {
|
||||
|
||||
/// Creates a tarball of save-analysis metadata, if available.
|
||||
pub fn analysis(build: &Build, compiler: &Compiler, target: &str) {
|
||||
println!("Dist analysis");
|
||||
|
||||
if build.config.channel != "nightly" {
|
||||
println!("\tskipping - not on nightly channel");
|
||||
return;
|
||||
}
|
||||
if compiler.host != build.config.build {
|
||||
println!("\tskipping - not a build host");
|
||||
if !build.config.rust_save_analysis {
|
||||
return
|
||||
}
|
||||
if compiler.stage != 2 {
|
||||
println!("\tskipping - not stage2");
|
||||
|
||||
println!("Dist analysis");
|
||||
|
||||
if compiler.host != build.config.build {
|
||||
println!("\tskipping, not a build host");
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,10 @@ pub fn install(build: &Build, stage: u32, host: &str) {
|
||||
install_sh(&build, "docs", "rust-docs", stage, host, &prefix,
|
||||
&docdir, &libdir, &mandir, &empty_dir);
|
||||
}
|
||||
if build.config.rust_save_analysis {
|
||||
install_sh(&build, "analysis", "rust-analysis", stage, host, &prefix,
|
||||
&docdir, &libdir, &mandir, &empty_dir);
|
||||
}
|
||||
install_sh(&build, "std", "rust-std", stage, host, &prefix,
|
||||
&docdir, &libdir, &mandir, &empty_dir);
|
||||
install_sh(&build, "rustc", "rustc", stage, host, &prefix,
|
||||
|
@ -524,7 +524,7 @@ impl Build {
|
||||
.env(format!("CFLAGS_{}", target), self.cflags(target).join(" "));
|
||||
}
|
||||
|
||||
if self.config.channel == "nightly" && compiler.is_final_stage(self) {
|
||||
if self.config.rust_save_analysis && compiler.is_final_stage(self) {
|
||||
cargo.env("RUSTC_SAVE_ANALYSIS", "api".to_string());
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@ fi
|
||||
if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then
|
||||
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=nightly"
|
||||
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp"
|
||||
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-save-analysis"
|
||||
|
||||
if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then
|
||||
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"
|
||||
|
@ -1974,6 +1974,22 @@ impl<'a> From<&'a str> for String {
|
||||
}
|
||||
}
|
||||
|
||||
// note: test pulls in libstd, which causes errors here
|
||||
#[cfg(not(test))]
|
||||
#[stable(feature = "string_from_box", since = "1.17.0")]
|
||||
impl From<Box<str>> for String {
|
||||
fn from(s: Box<str>) -> String {
|
||||
s.into_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "box_from_str", since = "1.17.0")]
|
||||
impl Into<Box<str>> for String {
|
||||
fn into(self) -> Box<str> {
|
||||
self.into_boxed_str()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "string_from_cow_str", since = "1.14.0")]
|
||||
impl<'a> From<Cow<'a, str>> for String {
|
||||
fn from(s: Cow<'a, str>) -> String {
|
||||
|
@ -1897,6 +1897,22 @@ impl<'a, T> From<Cow<'a, [T]>> for Vec<T> where [T]: ToOwned<Owned=Vec<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
// note: test pulls in libstd, which causes errors here
|
||||
#[cfg(not(test))]
|
||||
#[stable(feature = "vec_from_box", since = "1.17.0")]
|
||||
impl<T> From<Box<[T]>> for Vec<T> {
|
||||
fn from(s: Box<[T]>) -> Vec<T> {
|
||||
s.into_vec()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "box_from_vec", since = "1.17.0")]
|
||||
impl<T> Into<Box<[T]>> for Vec<T> {
|
||||
fn into(self) -> Box<[T]> {
|
||||
self.into_boxed_slice()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a> From<&'a str> for Vec<u8> {
|
||||
fn from(s: &'a str) -> Vec<u8> {
|
||||
|
@ -28,6 +28,7 @@
|
||||
#![feature(test)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(unicode)]
|
||||
#![feature(utf8_error_error_len)]
|
||||
|
||||
extern crate collections;
|
||||
extern crate test;
|
||||
|
@ -540,6 +540,36 @@ fn from_utf8_mostly_ascii() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_utf8_error() {
|
||||
macro_rules! test {
|
||||
($input: expr, $expected_valid_up_to: expr, $expected_error_len: expr) => {
|
||||
let error = from_utf8($input).unwrap_err();
|
||||
assert_eq!(error.valid_up_to(), $expected_valid_up_to);
|
||||
assert_eq!(error.error_len(), $expected_error_len);
|
||||
}
|
||||
}
|
||||
test!(b"A\xC3\xA9 \xFF ", 4, Some(1));
|
||||
test!(b"A\xC3\xA9 \x80 ", 4, Some(1));
|
||||
test!(b"A\xC3\xA9 \xC1 ", 4, Some(1));
|
||||
test!(b"A\xC3\xA9 \xC1", 4, Some(1));
|
||||
test!(b"A\xC3\xA9 \xC2", 4, None);
|
||||
test!(b"A\xC3\xA9 \xC2 ", 4, Some(1));
|
||||
test!(b"A\xC3\xA9 \xC2\xC0", 4, Some(1));
|
||||
test!(b"A\xC3\xA9 \xE0", 4, None);
|
||||
test!(b"A\xC3\xA9 \xE0\x9F", 4, Some(1));
|
||||
test!(b"A\xC3\xA9 \xE0\xA0", 4, None);
|
||||
test!(b"A\xC3\xA9 \xE0\xA0\xC0", 4, Some(2));
|
||||
test!(b"A\xC3\xA9 \xE0\xA0 ", 4, Some(2));
|
||||
test!(b"A\xC3\xA9 \xED\xA0\x80 ", 4, Some(1));
|
||||
test!(b"A\xC3\xA9 \xF1", 4, None);
|
||||
test!(b"A\xC3\xA9 \xF1\x80", 4, None);
|
||||
test!(b"A\xC3\xA9 \xF1\x80\x80", 4, None);
|
||||
test!(b"A\xC3\xA9 \xF1 ", 4, Some(1));
|
||||
test!(b"A\xC3\xA9 \xF1\x80 ", 4, Some(2));
|
||||
test!(b"A\xC3\xA9 \xF1\x80\x80 ", 4, Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_as_bytes() {
|
||||
// no null
|
||||
|
@ -125,13 +125,14 @@ Section: Creating a string
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Utf8Error {
|
||||
valid_up_to: usize,
|
||||
error_len: Option<u8>,
|
||||
}
|
||||
|
||||
impl Utf8Error {
|
||||
/// Returns the index in the given string up to which valid UTF-8 was
|
||||
/// verified.
|
||||
///
|
||||
/// It is the maximum index such that `from_utf8(input[..index])`
|
||||
/// It is the maximum index such that `from_utf8(&input[..index])`
|
||||
/// would return `Ok(_)`.
|
||||
///
|
||||
/// # Examples
|
||||
@ -152,6 +153,23 @@ impl Utf8Error {
|
||||
/// ```
|
||||
#[stable(feature = "utf8_error", since = "1.5.0")]
|
||||
pub fn valid_up_to(&self) -> usize { self.valid_up_to }
|
||||
|
||||
/// Provide more information about the failure:
|
||||
///
|
||||
/// * `None`: the end of the input was reached unexpectedly.
|
||||
/// `self.valid_up_to()` is 1 to 3 bytes from the end of the input.
|
||||
/// If a byte stream (such as a file or a network socket) is being decoded incrementally,
|
||||
/// this could be a valid `char` whose UTF-8 byte sequence is spanning multiple chunks.
|
||||
///
|
||||
/// * `Some(len)`: an unexpected byte was encountered.
|
||||
/// The length provided is that of the invalid byte sequence
|
||||
/// that starts at the index given by `valid_up_to()`.
|
||||
/// Decoding should resume after that sequence
|
||||
/// (after inserting a U+FFFD REPLACEMENT CHARACTER) in case of lossy decoding.
|
||||
#[unstable(feature = "utf8_error_error_len", reason ="new", issue = "40494")]
|
||||
pub fn error_len(&self) -> Option<usize> {
|
||||
self.error_len.map(|len| len as usize)
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a slice of bytes to a string slice.
|
||||
@ -300,7 +318,12 @@ pub unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl fmt::Display for Utf8Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "invalid utf-8: invalid byte near index {}", self.valid_up_to)
|
||||
if let Some(error_len) = self.error_len {
|
||||
write!(f, "invalid utf-8 sequence of {} bytes from index {}",
|
||||
error_len, self.valid_up_to)
|
||||
} else {
|
||||
write!(f, "incomplete utf-8 byte sequence from index {}", self.valid_up_to)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1241,17 +1264,20 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
|
||||
|
||||
while index < len {
|
||||
let old_offset = index;
|
||||
macro_rules! err { () => {{
|
||||
return Err(Utf8Error {
|
||||
valid_up_to: old_offset
|
||||
})
|
||||
}}}
|
||||
macro_rules! err {
|
||||
($error_len: expr) => {
|
||||
return Err(Utf8Error {
|
||||
valid_up_to: old_offset,
|
||||
error_len: $error_len,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! next { () => {{
|
||||
index += 1;
|
||||
// we needed data, but there was none: error!
|
||||
if index >= len {
|
||||
err!()
|
||||
err!(None)
|
||||
}
|
||||
v[index]
|
||||
}}}
|
||||
@ -1259,7 +1285,6 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
|
||||
let first = v[index];
|
||||
if first >= 128 {
|
||||
let w = UTF8_CHAR_WIDTH[first as usize];
|
||||
let second = next!();
|
||||
// 2-byte encoding is for codepoints \u{0080} to \u{07ff}
|
||||
// first C2 80 last DF BF
|
||||
// 3-byte encoding is for codepoints \u{0800} to \u{ffff}
|
||||
@ -1279,25 +1304,36 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
|
||||
// UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
|
||||
// %xF4 %x80-8F 2( UTF8-tail )
|
||||
match w {
|
||||
2 => if second & !CONT_MASK != TAG_CONT_U8 {err!()},
|
||||
2 => if next!() & !CONT_MASK != TAG_CONT_U8 {
|
||||
err!(Some(1))
|
||||
},
|
||||
3 => {
|
||||
match (first, second, next!() & !CONT_MASK) {
|
||||
(0xE0 , 0xA0 ... 0xBF, TAG_CONT_U8) |
|
||||
(0xE1 ... 0xEC, 0x80 ... 0xBF, TAG_CONT_U8) |
|
||||
(0xED , 0x80 ... 0x9F, TAG_CONT_U8) |
|
||||
(0xEE ... 0xEF, 0x80 ... 0xBF, TAG_CONT_U8) => {}
|
||||
_ => err!()
|
||||
match (first, next!()) {
|
||||
(0xE0 , 0xA0 ... 0xBF) |
|
||||
(0xE1 ... 0xEC, 0x80 ... 0xBF) |
|
||||
(0xED , 0x80 ... 0x9F) |
|
||||
(0xEE ... 0xEF, 0x80 ... 0xBF) => {}
|
||||
_ => err!(Some(1))
|
||||
}
|
||||
if next!() & !CONT_MASK != TAG_CONT_U8 {
|
||||
err!(Some(2))
|
||||
}
|
||||
}
|
||||
4 => {
|
||||
match (first, second, next!() & !CONT_MASK, next!() & !CONT_MASK) {
|
||||
(0xF0 , 0x90 ... 0xBF, TAG_CONT_U8, TAG_CONT_U8) |
|
||||
(0xF1 ... 0xF3, 0x80 ... 0xBF, TAG_CONT_U8, TAG_CONT_U8) |
|
||||
(0xF4 , 0x80 ... 0x8F, TAG_CONT_U8, TAG_CONT_U8) => {}
|
||||
_ => err!()
|
||||
match (first, next!()) {
|
||||
(0xF0 , 0x90 ... 0xBF) |
|
||||
(0xF1 ... 0xF3, 0x80 ... 0xBF) |
|
||||
(0xF4 , 0x80 ... 0x8F) => {}
|
||||
_ => err!(Some(1))
|
||||
}
|
||||
if next!() & !CONT_MASK != TAG_CONT_U8 {
|
||||
err!(Some(2))
|
||||
}
|
||||
if next!() & !CONT_MASK != TAG_CONT_U8 {
|
||||
err!(Some(3))
|
||||
}
|
||||
}
|
||||
_ => err!()
|
||||
_ => err!(Some(1))
|
||||
}
|
||||
index += 1;
|
||||
} else {
|
||||
|
@ -325,7 +325,7 @@ impl CString {
|
||||
}
|
||||
|
||||
/// Converts this `CString` into a boxed `CStr`.
|
||||
#[unstable(feature = "into_boxed_c_str", issue = "0")]
|
||||
#[unstable(feature = "into_boxed_c_str", issue = "40380")]
|
||||
pub fn into_boxed_c_str(self) -> Box<CStr> {
|
||||
unsafe { mem::transmute(self.into_inner()) }
|
||||
}
|
||||
@ -415,6 +415,20 @@ impl<'a> From<&'a CStr> for Box<CStr> {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "c_string_from_box", since = "1.17.0")]
|
||||
impl From<Box<CStr>> for CString {
|
||||
fn from(s: Box<CStr>) -> CString {
|
||||
s.into_c_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "box_from_c_string", since = "1.17.0")]
|
||||
impl Into<Box<CStr>> for CString {
|
||||
fn into(self) -> Box<CStr> {
|
||||
self.into_boxed_c_str()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "default_box_extra", since = "1.17.0")]
|
||||
impl Default for Box<CStr> {
|
||||
fn default() -> Box<CStr> {
|
||||
@ -728,6 +742,12 @@ impl CStr {
|
||||
pub fn to_string_lossy(&self) -> Cow<str> {
|
||||
String::from_utf8_lossy(self.to_bytes())
|
||||
}
|
||||
|
||||
/// Converts a `Box<CStr>` into a `CString` without copying or allocating.
|
||||
#[unstable(feature = "into_boxed_c_str", issue = "40380")]
|
||||
pub fn into_c_string(self: Box<CStr>) -> CString {
|
||||
unsafe { mem::transmute(self) }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -922,12 +942,11 @@ mod tests {
|
||||
fn into_boxed() {
|
||||
let orig: &[u8] = b"Hello, world!\0";
|
||||
let cstr = CStr::from_bytes_with_nul(orig).unwrap();
|
||||
let cstring = cstr.to_owned();
|
||||
let box1: Box<CStr> = Box::from(cstr);
|
||||
let box2 = cstring.into_boxed_c_str();
|
||||
assert_eq!(cstr, &*box1);
|
||||
assert_eq!(box1, box2);
|
||||
assert_eq!(&*box2, cstr);
|
||||
let boxed: Box<CStr> = Box::from(cstr);
|
||||
let cstring = cstr.to_owned().into_boxed_c_str().into_c_string();
|
||||
assert_eq!(cstr, &*boxed);
|
||||
assert_eq!(&*boxed, &*cstring);
|
||||
assert_eq!(&*cstring, cstr);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -260,7 +260,7 @@ impl OsString {
|
||||
///
|
||||
/// let b: Box<OsStr> = s.into_boxed_os_str();
|
||||
/// ```
|
||||
#[unstable(feature = "into_boxed_os_str", issue = "0")]
|
||||
#[unstable(feature = "into_boxed_os_str", issue = "40380")]
|
||||
pub fn into_boxed_os_str(self) -> Box<OsStr> {
|
||||
unsafe { mem::transmute(self.inner.into_box()) }
|
||||
}
|
||||
@ -506,6 +506,13 @@ impl OsStr {
|
||||
self.inner.inner.len()
|
||||
}
|
||||
|
||||
/// Converts a `Box<OsStr>` into an `OsString` without copying or allocating.
|
||||
#[unstable(feature = "into_boxed_os_str", issue = "40380")]
|
||||
pub fn into_os_string(self: Box<OsStr>) -> OsString {
|
||||
let inner: Box<Slice> = unsafe { mem::transmute(self) };
|
||||
OsString { inner: Buf::from_box(inner) }
|
||||
}
|
||||
|
||||
/// Gets the underlying byte representation.
|
||||
///
|
||||
/// Note: it is *crucial* that this API is private, to avoid
|
||||
@ -522,6 +529,20 @@ impl<'a> From<&'a OsStr> for Box<OsStr> {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "os_string_from_box", since = "1.17.0")]
|
||||
impl<'a> From<Box<OsStr>> for OsString {
|
||||
fn from(boxed: Box<OsStr>) -> OsString {
|
||||
boxed.into_os_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "box_from_c_string", since = "1.17.0")]
|
||||
impl Into<Box<OsStr>> for OsString {
|
||||
fn into(self) -> Box<OsStr> {
|
||||
self.into_boxed_os_str()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "box_default_extra", since = "1.17.0")]
|
||||
impl Default for Box<OsStr> {
|
||||
fn default() -> Box<OsStr> {
|
||||
@ -830,12 +851,11 @@ mod tests {
|
||||
fn into_boxed() {
|
||||
let orig = "Hello, world!";
|
||||
let os_str = OsStr::new(orig);
|
||||
let os_string = os_str.to_owned();
|
||||
let box1: Box<OsStr> = Box::from(os_str);
|
||||
let box2 = os_string.into_boxed_os_str();
|
||||
assert_eq!(os_str, &*box1);
|
||||
assert_eq!(box1, box2);
|
||||
assert_eq!(&*box2, os_str);
|
||||
let boxed: Box<OsStr> = Box::from(os_str);
|
||||
let os_string = os_str.to_owned().into_boxed_os_str().into_os_string();
|
||||
assert_eq!(os_str, &*boxed);
|
||||
assert_eq!(&*boxed, &*os_string);
|
||||
assert_eq!(&*os_string, os_str);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1196,7 +1196,7 @@ impl PathBuf {
|
||||
}
|
||||
|
||||
/// Converts this `PathBuf` into a boxed `Path`.
|
||||
#[unstable(feature = "into_boxed_path", issue = "0")]
|
||||
#[unstable(feature = "into_boxed_path", issue = "40380")]
|
||||
pub fn into_boxed_path(self) -> Box<Path> {
|
||||
unsafe { mem::transmute(self.inner.into_boxed_os_str()) }
|
||||
}
|
||||
@ -1210,6 +1210,20 @@ impl<'a> From<&'a Path> for Box<Path> {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "path_buf_from_box", since = "1.17.0")]
|
||||
impl<'a> From<Box<Path>> for PathBuf {
|
||||
fn from(boxed: Box<Path>) -> PathBuf {
|
||||
boxed.into_path_buf()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "box_from_path_buf", since = "1.17.0")]
|
||||
impl Into<Box<Path>> for PathBuf {
|
||||
fn into(self) -> Box<Path> {
|
||||
self.into_boxed_path()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "box_default_extra", since = "1.17.0")]
|
||||
impl Default for Box<Path> {
|
||||
fn default() -> Box<Path> {
|
||||
@ -2089,6 +2103,13 @@ impl Path {
|
||||
pub fn is_dir(&self) -> bool {
|
||||
fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Converts a `Box<Path>` into a `PathBuf` without copying or allocating.
|
||||
#[unstable(feature = "into_boxed_path", issue = "40380")]
|
||||
pub fn into_path_buf(self: Box<Path>) -> PathBuf {
|
||||
let inner: Box<OsStr> = unsafe { mem::transmute(self) };
|
||||
PathBuf { inner: OsString::from(inner) }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -3703,12 +3724,11 @@ mod tests {
|
||||
fn into_boxed() {
|
||||
let orig: &str = "some/sort/of/path";
|
||||
let path = Path::new(orig);
|
||||
let path_buf = path.to_owned();
|
||||
let box1: Box<Path> = Box::from(path);
|
||||
let box2 = path_buf.into_boxed_path();
|
||||
assert_eq!(path, &*box1);
|
||||
assert_eq!(box1, box2);
|
||||
assert_eq!(&*box2, path);
|
||||
let boxed: Box<Path> = Box::from(path);
|
||||
let path_buf = path.to_owned().into_boxed_path().into_path_buf();
|
||||
assert_eq!(path, &*boxed);
|
||||
assert_eq!(&*boxed, &*path_buf);
|
||||
assert_eq!(&*path_buf, path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -104,6 +104,12 @@ impl Buf {
|
||||
pub fn into_box(self) -> Box<Slice> {
|
||||
unsafe { mem::transmute(self.inner.into_boxed_slice()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_box(boxed: Box<Slice>) -> Buf {
|
||||
let inner: Box<[u8]> = unsafe { mem::transmute(boxed) };
|
||||
Buf { inner: inner.into_vec() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Slice {
|
||||
|
@ -104,6 +104,12 @@ impl Buf {
|
||||
pub fn into_box(self) -> Box<Slice> {
|
||||
unsafe { mem::transmute(self.inner.into_boxed_slice()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_box(boxed: Box<Slice>) -> Buf {
|
||||
let inner: Box<[u8]> = unsafe { mem::transmute(boxed) };
|
||||
Buf { inner: inner.into_vec() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Slice {
|
||||
|
@ -97,6 +97,12 @@ impl Buf {
|
||||
pub fn into_box(self) -> Box<Slice> {
|
||||
unsafe { mem::transmute(self.inner.into_box()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_box(boxed: Box<Slice>) -> Buf {
|
||||
let inner: Box<Wtf8> = unsafe { mem::transmute(boxed) };
|
||||
Buf { inner: Wtf8Buf::from_box(inner) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Slice {
|
||||
|
@ -351,6 +351,12 @@ impl Wtf8Buf {
|
||||
pub fn into_box(self) -> Box<Wtf8> {
|
||||
unsafe { mem::transmute(self.bytes.into_boxed_slice()) }
|
||||
}
|
||||
|
||||
/// Converts a `Box<Wtf8>` into a `Wtf8Buf`.
|
||||
pub fn from_box(boxed: Box<Wtf8>) -> Wtf8Buf {
|
||||
let bytes: Box<[u8]> = unsafe { mem::transmute(boxed) };
|
||||
Wtf8Buf { bytes: bytes.into_vec() }
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new WTF-8 string from an iterator of code points.
|
||||
|
Loading…
Reference in New Issue
Block a user