diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 830b9dc475d..765cdc29a9f 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -317,10 +317,10 @@ fn iter_after(mut iter: I, mut prefix: J) -> Option // See note at the top of this module to understand why these are used: fn os_str_as_u8_slice(s: &OsStr) -> &[u8] { - unsafe { mem::transmute(s) } + unsafe { &*(s as *const OsStr as *const [u8]) } } unsafe fn u8_slice_as_os_str(s: &[u8]) -> &OsStr { - mem::transmute(s) + &*(s as *const [u8] as *const OsStr) } // Detect scheme on Redox @@ -1334,15 +1334,16 @@ impl PathBuf { /// [`Path`]: struct.Path.html #[stable(feature = "into_boxed_path", since = "1.20.0")] pub fn into_boxed_path(self) -> Box { - unsafe { mem::transmute(self.inner.into_boxed_os_str()) } + let rw = Box::into_raw(self.inner.into_boxed_os_str()) as *mut Path; + unsafe { Box::from_raw(rw) } } } #[stable(feature = "box_from_path", since = "1.17.0")] impl<'a> From<&'a Path> for Box { fn from(path: &'a Path) -> Box { - let boxed: Box = path.inner.into(); - unsafe { mem::transmute(boxed) } + let rw = Box::into_raw(Box::from(&path.inner)) as *mut Path; + unsafe { Box::from_raw(rw) } } } @@ -1589,7 +1590,7 @@ impl Path { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn new + ?Sized>(s: &S) -> &Path { - unsafe { mem::transmute(s.as_ref()) } + unsafe { &*(s.as_ref() as *const OsStr as *const Path) } } /// Yields the underlying [`OsStr`] slice. @@ -2312,8 +2313,8 @@ impl Path { /// [`PathBuf`]: struct.PathBuf.html #[stable(feature = "into_boxed_path", since = "1.20.0")] pub fn into_path_buf(self: Box) -> PathBuf { - let inner: Box = unsafe { mem::transmute(self) }; - PathBuf { inner: OsString::from(inner) } + let rw = Box::into_raw(self) as *mut OsStr; + unsafe { Box::from_raw(rw) } } }