Rollup merge of #50995 - fbstj:patch-1, r=cramertj

move type out of unsafe block

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

move the union definition outside of the unsafe block as it's definition is not unsafe
This commit is contained in:
kennytm 2018-05-24 16:02:46 +08:00
commit 99de8ab38b
No known key found for this signature in database
GPG Key ID: FEF6C8051D0E013C
1 changed files with 4 additions and 6 deletions

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