Skip to content

Commit

Permalink
Rollup merge of rust-lang#50995 - fbstj:patch-1, r=cramertj
Browse files Browse the repository at this point in the history
move type out of unsafe block

from rust-lang#50863 (comment)

move the union definition outside of the unsafe block as it's definition is not unsafe
  • Loading branch information
kennytm committed May 24, 2018
2 parents 79a2676 + 1977c62 commit 99de8ab
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 99de8ab

Please sign in to comment.