about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-05-24 16:02:46 +0800
committerkennytm <kennytm@gmail.com>2018-05-24 17:34:54 +0800
commit99de8ab38b282b83553a10e5dd0e83976ee33af0 (patch)
tree7f8789632d41ab46f46172a142bc9932404c0ce9
parent79a2676ce0ad6196b6d212c65147e78bf797fe29 (diff)
parent1977c62339acceabe711d8ca6bf9404475c7f75d (diff)
downloadrust-99de8ab38b282b83553a10e5dd0e83976ee33af0.tar.gz
rust-99de8ab38b282b83553a10e5dd0e83976ee33af0.zip
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
-rw-r--r--src/libcore/str/mod.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs
index 70aaf10f421..13d808ede5f 100644
--- a/src/libcore/str/mod.rs
+++ b/src/libcore/str/mod.rs
@@ -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