@@ -381,12 +381,6 @@ pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> {
381
381
Ok ( unsafe { from_utf8_unchecked_mut ( v) } )
382
382
}
383
383
384
- #[ repr( C ) ]
385
- union StrOrSlice < ' a > {
386
- str : & ' a str ,
387
- slice : & ' a [ u8 ] ,
388
- }
389
-
390
384
/// Converts a slice of bytes to a string slice without checking
391
385
/// that the string contains valid UTF-8.
392
386
///
@@ -422,11 +416,11 @@ union StrOrSlice<'a> {
422
416
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
423
417
#[ rustc_const_unstable( feature = "const_str_from_utf8_unchecked" , issue = "75196" ) ]
424
418
#[ allow( unused_attributes) ]
425
- #[ allow_internal_unstable( const_fn_union ) ]
419
+ #[ allow_internal_unstable( const_fn_transmute ) ]
426
420
pub const unsafe fn from_utf8_unchecked ( v : & [ u8 ] ) -> & str {
427
421
// SAFETY: the caller must guarantee that the bytes `v` are valid UTF-8.
428
422
// Also relies on `&str` and `&[u8]` having the same layout.
429
- unsafe { StrOrSlice { slice : v } . str }
423
+ unsafe { mem :: transmute ( self ) }
430
424
}
431
425
432
426
/// Converts a slice of bytes to a string slice without checking
@@ -2355,10 +2349,10 @@ impl str {
2355
2349
#[ rustc_const_stable( feature = "str_as_bytes" , since = "1.32.0" ) ]
2356
2350
#[ inline( always) ]
2357
2351
#[ allow( unused_attributes) ]
2358
- #[ allow_internal_unstable( const_fn_union ) ]
2352
+ #[ allow_internal_unstable( const_fn_transmute ) ]
2359
2353
pub const fn as_bytes ( & self ) -> & [ u8 ] {
2360
2354
// SAFETY: const sound because we transmute two types with the same layout
2361
- unsafe { StrOrSlice { str : self } . slice }
2355
+ unsafe { mem :: transmute ( self ) }
2362
2356
}
2363
2357
2364
2358
/// Converts a mutable string slice to a mutable byte slice.
0 commit comments