move type def out of unsafe block

from https://github.com/rust-lang/rust/pull/50863#discussion_r190213000

move the union definition outside of the unsafe block
This commit is contained in:
Joe ST 2018-05-23 15:01:11 +01:00 committed by GitHub
parent c3733a770e
commit 1977c62339
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2246,13 +2246,11 @@ impl str {
#[inline(always)]
#[rustc_const_unstable(feature="const_str_as_bytes")]
pub const fn as_bytes(&self) -> &[u8] {
unsafe {
union Slices<'a> {
str: &'a str,
slice: &'a [u8],
}
Slices { str: self }.slice
union Slices<'a> {
str: &'a str,
slice: &'a [u8],
}
unsafe { Slices { str: self }.slice }
}
/// Converts a mutable string slice to a mutable byte slice. To convert the