@@ -260,7 +260,8 @@ impl OsString {
260260 /// ```
261261 #[ stable( feature = "into_boxed_os_str" , since = "1.20.0" ) ]
262262 pub fn into_boxed_os_str ( self ) -> Box < OsStr > {
263- unsafe { mem:: transmute ( self . inner . into_box ( ) ) }
263+ let rw = Box :: into_raw ( self . inner . into_box ( ) ) as * mut OsStr ;
264+ unsafe { Box :: from_raw ( rw) }
264265 }
265266}
266267
@@ -394,7 +395,7 @@ impl OsStr {
394395 }
395396
396397 fn from_inner ( inner : & Slice ) -> & OsStr {
397- unsafe { mem :: transmute ( inner) }
398+ unsafe { & * ( inner as * const Slice as * const OsStr ) }
398399 }
399400
400401 /// Yields a [`&str`] slice if the `OsStr` is valid Unicode.
@@ -511,23 +512,24 @@ impl OsStr {
511512 /// [`OsString`]: struct.OsString.html
512513 #[ stable( feature = "into_boxed_os_str" , since = "1.20.0" ) ]
513514 pub fn into_os_string ( self : Box < OsStr > ) -> OsString {
514- let inner : Box < Slice > = unsafe { mem :: transmute ( self ) } ;
515- OsString { inner : Buf :: from_box ( inner ) }
515+ let boxed = unsafe { Box :: from_raw ( Box :: into_raw ( self ) as * mut Slice ) } ;
516+ OsString { inner : Buf :: from_box ( boxed ) }
516517 }
517518
518519 /// Gets the underlying byte representation.
519520 ///
520521 /// Note: it is *crucial* that this API is private, to avoid
521522 /// revealing the internal, platform-specific encodings.
522523 fn bytes ( & self ) -> & [ u8 ] {
523- unsafe { mem :: transmute ( & self . inner ) }
524+ & self . inner . inner
524525 }
525526}
526527
527528#[ stable( feature = "box_from_os_str" , since = "1.17.0" ) ]
528529impl < ' a > From < & ' a OsStr > for Box < OsStr > {
529530 fn from ( s : & ' a OsStr ) -> Box < OsStr > {
530- unsafe { mem:: transmute ( s. inner . into_box ( ) ) }
531+ let rw = Box :: into_raw ( s. inner . into_box ( ) ) as * mut OsStr ;
532+ unsafe { Box :: from_raw ( rw) }
531533 }
532534}
533535
@@ -548,7 +550,8 @@ impl From<OsString> for Box<OsStr> {
548550#[ stable( feature = "box_default_extra" , since = "1.17.0" ) ]
549551impl Default for Box < OsStr > {
550552 fn default ( ) -> Box < OsStr > {
551- unsafe { mem:: transmute ( Slice :: empty_box ( ) ) }
553+ let rw = Box :: into_raw ( Slice :: empty_box ( ) ) as * mut OsStr ;
554+ unsafe { Box :: from_raw ( rw) }
552555 }
553556}
554557
0 commit comments