@@ -260,7 +260,8 @@ impl OsString {
260
260
/// ```
261
261
#[ stable( feature = "into_boxed_os_str" , since = "1.20.0" ) ]
262
262
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) }
264
265
}
265
266
}
266
267
@@ -394,7 +395,7 @@ impl OsStr {
394
395
}
395
396
396
397
fn from_inner ( inner : & Slice ) -> & OsStr {
397
- unsafe { mem :: transmute ( inner) }
398
+ unsafe { & * ( inner as * const Slice as * const OsStr ) }
398
399
}
399
400
400
401
/// Yields a [`&str`] slice if the `OsStr` is valid Unicode.
@@ -511,23 +512,24 @@ impl OsStr {
511
512
/// [`OsString`]: struct.OsString.html
512
513
#[ stable( feature = "into_boxed_os_str" , since = "1.20.0" ) ]
513
514
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 ) }
516
517
}
517
518
518
519
/// Gets the underlying byte representation.
519
520
///
520
521
/// Note: it is *crucial* that this API is private, to avoid
521
522
/// revealing the internal, platform-specific encodings.
522
523
fn bytes ( & self ) -> & [ u8 ] {
523
- unsafe { mem :: transmute ( & self . inner ) }
524
+ & self . inner . inner
524
525
}
525
526
}
526
527
527
528
#[ stable( feature = "box_from_os_str" , since = "1.17.0" ) ]
528
529
impl < ' a > From < & ' a OsStr > for Box < OsStr > {
529
530
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) }
531
533
}
532
534
}
533
535
@@ -548,7 +550,8 @@ impl From<OsString> for Box<OsStr> {
548
550
#[ stable( feature = "box_default_extra" , since = "1.17.0" ) ]
549
551
impl Default for Box < OsStr > {
550
552
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) }
552
555
}
553
556
}
554
557
0 commit comments