Skip to content

Commit 99de8ab

Browse files
committed
Rollup merge of rust-lang#50995 - fbstj:patch-1, r=cramertj
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
2 parents 79a2676 + 1977c62 commit 99de8ab

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/libcore/str/mod.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -2246,13 +2246,11 @@ impl str {
22462246
#[inline(always)]
22472247
#[rustc_const_unstable(feature="const_str_as_bytes")]
22482248
pub const fn as_bytes(&self) -> &[u8] {
2249-
unsafe {
2250-
union Slices<'a> {
2251-
str: &'a str,
2252-
slice: &'a [u8],
2253-
}
2254-
Slices { str: self }.slice
2249+
union Slices<'a> {
2250+
str: &'a str,
2251+
slice: &'a [u8],
22552252
}
2253+
unsafe { Slices { str: self }.slice }
22562254
}
22572255

22582256
/// Converts a mutable string slice to a mutable byte slice. To convert the

0 commit comments

Comments
 (0)