From 90a17e949c0bc7e4e8159c1d48d1cb9dc38a35c9 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Sun, 7 Jan 2018 17:08:01 -0500 Subject: [PATCH 1/6] Replace many transmutes with casts or safe code --- src/bootstrap/cache.rs | 19 +++++++++++-------- src/librustc/ty/mod.rs | 4 ++-- src/librustc_data_structures/blake2b.rs | 3 +-- src/librustc_data_structures/stable_hasher.rs | 10 ++-------- src/librustc_trans/type_.rs | 3 +-- src/libstd/error.rs | 7 +++---- src/libstd/sys/redox/args.rs | 3 +-- src/libstd/sys/redox/ext/ffi.rs | 3 +-- src/libstd/sys/redox/os_str.rs | 14 +++++++------- src/libstd/sys/unix/os_str.rs | 14 +++++++------- src/libstd/sys/wasm/os_str.rs | 14 +++++++------- src/libstd/sys/windows/os_str.rs | 16 +++++++++------- src/libstd_unicode/lossy.rs | 3 +-- 13 files changed, 53 insertions(+), 60 deletions(-) diff --git a/src/bootstrap/cache.rs b/src/bootstrap/cache.rs index c27493158826c..f809504dac352 100644 --- a/src/bootstrap/cache.rs +++ b/src/bootstrap/cache.rs @@ -17,7 +17,6 @@ use std::ffi::OsStr; use std::fmt; use std::hash::{Hash, Hasher}; use std::marker::PhantomData; -use std::mem; use std::ops::Deref; use std::path::{Path, PathBuf}; use std::sync::Mutex; @@ -114,7 +113,8 @@ impl Deref for Interned { type Target = str; fn deref(&self) -> &'static str { let l = INTERNER.strs.lock().unwrap(); - unsafe { mem::transmute::<&str, &'static str>(l.get(*self)) } + let s: &str = l.get(*self).as_ref(); + unsafe { &*(s *const _) } } } @@ -122,35 +122,38 @@ impl Deref for Interned { type Target = Path; fn deref(&self) -> &'static Path { let l = INTERNER.paths.lock().unwrap(); - unsafe { mem::transmute::<&Path, &'static Path>(l.get(*self)) } + let p: &Path = l.get(*self).as_ref(); + unsafe { &*(p *const _) } } } impl AsRef for Interned { fn as_ref(&self) -> &'static Path { - let l = INTERNER.paths.lock().unwrap(); - unsafe { mem::transmute::<&Path, &'static Path>(l.get(*self)) } + &*self } } impl AsRef for Interned { fn as_ref(&self) -> &'static Path { let l = INTERNER.strs.lock().unwrap(); - unsafe { mem::transmute::<&Path, &'static Path>(l.get(*self).as_ref()) } + let p: &Path = l.get(*self).as_ref(); + unsafe { &*(p *const _) } } } impl AsRef for Interned { fn as_ref(&self) -> &'static OsStr { let l = INTERNER.paths.lock().unwrap(); - unsafe { mem::transmute::<&OsStr, &'static OsStr>(l.get(*self).as_ref()) } + let s: &OsStr = l.get(*self).as_ref(); + unsafe { &*(s *const _) } } } impl AsRef for Interned { fn as_ref(&self) -> &'static OsStr { let l = INTERNER.strs.lock().unwrap(); - unsafe { mem::transmute::<&OsStr, &'static OsStr>(l.get(*self).as_ref()) } + let s: &OsStr = l.get(*self).as_ref(); + unsafe { &*(s *const _) } } } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index e5f6ac8853067..fe4f01a8011b2 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -46,7 +46,6 @@ use std::ops::Deref; use std::rc::Rc; use std::slice; use std::vec::IntoIter; -use std::mem; use syntax::ast::{self, DUMMY_NODE_ID, Name, Ident, NodeId}; use syntax::attr; use syntax::ext::hygiene::{Mark, SyntaxContext}; @@ -592,7 +591,8 @@ impl<'tcx> serialize::UseSpecializedDecodable for &'tcx Slice> {} impl Slice { pub fn empty<'a>() -> &'a Slice { unsafe { - mem::transmute(slice::from_raw_parts(0x1 as *const T, 0)) + let slice = slice::from_raw_parts(0x1 as *const T, 0); + &*(slice as *const [T] as *const Slice) } } } diff --git a/src/librustc_data_structures/blake2b.rs b/src/librustc_data_structures/blake2b.rs index 6b8bf8df0d33f..76ef301fb1789 100644 --- a/src/librustc_data_structures/blake2b.rs +++ b/src/librustc_data_structures/blake2b.rs @@ -128,8 +128,7 @@ fn blake2b_compress(ctx: &mut Blake2bCtx, last: bool) { // before it's overwritten. let m: &mut [u64; 16] = unsafe { - let b: &mut [u8; 128] = &mut ctx.b; - ::std::mem::transmute(b) + &*(&mut ctx.b as *mut [u8; 128] as *mut [u64; 16]) }; if cfg!(target_endian = "big") { diff --git a/src/librustc_data_structures/stable_hasher.rs b/src/librustc_data_structures/stable_hasher.rs index d82b712b5b14b..c325a3cdd17de 100644 --- a/src/librustc_data_structures/stable_hasher.rs +++ b/src/librustc_data_structures/stable_hasher.rs @@ -241,10 +241,7 @@ impl HashStable for f32 { fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - let val: u32 = unsafe { - ::std::mem::transmute(*self) - }; - val.hash_stable(ctx, hasher); + self.to_bits().hash_stable(ctx, hasher); } } @@ -252,10 +249,7 @@ impl HashStable for f64 { fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - let val: u64 = unsafe { - ::std::mem::transmute(*self) - }; - val.hash_stable(ctx, hasher); + self.to_bits().hash_stable(ctx, hasher); } } diff --git a/src/librustc_trans/type_.rs b/src/librustc_trans/type_.rs index 6cbe175d4d8d5..6597e0b76fe15 100644 --- a/src/librustc_trans/type_.rs +++ b/src/librustc_trans/type_.rs @@ -21,7 +21,6 @@ use rustc::ty::layout::{self, Align, Size}; use std::ffi::CString; use std::fmt; -use std::mem; use std::ptr; use libc::c_uint; @@ -59,7 +58,7 @@ impl Type { } pub fn to_ref_slice(slice: &[Type]) -> &[TypeRef] { - unsafe { mem::transmute(slice) } + unsafe { &*(slice as *const [Type] as *const [TypeRef]) } } pub fn void(ccx: &CrateContext) -> Type { diff --git a/src/libstd/error.rs b/src/libstd/error.rs index eb5022ad5776a..cc48be83874f5 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -59,7 +59,6 @@ use char; use convert; use core::array; use fmt::{self, Debug, Display}; -use mem::transmute; use num; use str; use string; @@ -491,11 +490,11 @@ impl Error + Send { #[stable(feature = "error_downcast", since = "1.3.0")] /// Attempt to downcast the box to a concrete type. pub fn downcast(self: Box) - -> Result, Box> { + -> Result, Box> { let err: Box = self; ::downcast(err).map_err(|s| unsafe { // reapply the Send marker - transmute::, Box>(s) + Box::from_raw(Box::into_raw(s) as *mut Self) }) } } @@ -509,7 +508,7 @@ impl Error + Send + Sync { let err: Box = self; ::downcast(err).map_err(|s| unsafe { // reapply the Send+Sync marker - transmute::, Box>(s) + Box::from_raw(Box::into_raw(s) as *mut Self) }) } } diff --git a/src/libstd/sys/redox/args.rs b/src/libstd/sys/redox/args.rs index 59ae2a74a6ddd..afda25a367cdd 100644 --- a/src/libstd/sys/redox/args.rs +++ b/src/libstd/sys/redox/args.rs @@ -57,7 +57,6 @@ impl DoubleEndedIterator for Args { mod imp { use os::unix::prelude::*; - use mem; use ffi::{CStr, OsString}; use marker::PhantomData; use libc; @@ -105,7 +104,7 @@ mod imp { } fn get_global_ptr() -> *mut Option>>> { - unsafe { mem::transmute(&GLOBAL_ARGS_PTR) } + unsafe { &mut GLOBAL_ARGS_PTR as *mut _ as *mut _ } } } diff --git a/src/libstd/sys/redox/ext/ffi.rs b/src/libstd/sys/redox/ext/ffi.rs index d59b4fc0b70b8..06968bc4871ab 100644 --- a/src/libstd/sys/redox/ext/ffi.rs +++ b/src/libstd/sys/redox/ext/ffi.rs @@ -13,7 +13,6 @@ #![stable(feature = "rust1", since = "1.0.0")] use ffi::{OsStr, OsString}; -use mem; use sys::os_str::Buf; use sys_common::{FromInner, IntoInner, AsInner}; @@ -53,7 +52,7 @@ pub trait OsStrExt { #[stable(feature = "rust1", since = "1.0.0")] impl OsStrExt for OsStr { fn from_bytes(slice: &[u8]) -> &OsStr { - unsafe { mem::transmute(slice) } + unsafe { &*(slice as *const [u8] as *const OsStr) } } fn as_bytes(&self) -> &[u8] { &self.as_inner().inner diff --git a/src/libstd/sys/redox/os_str.rs b/src/libstd/sys/redox/os_str.rs index 655bfdb916707..564eaf2bde20a 100644 --- a/src/libstd/sys/redox/os_str.rs +++ b/src/libstd/sys/redox/os_str.rs @@ -14,7 +14,6 @@ use borrow::Cow; use fmt; use str; -use mem; use rc::Rc; use sync::Arc; use sys_common::{AsInner, IntoInner}; @@ -105,7 +104,7 @@ impl Buf { } pub fn as_slice(&self) -> &Slice { - unsafe { mem::transmute(&*self.inner) } + &*(&*self.inner as *const [u8] as *const Slice) } pub fn into_string(self) -> Result { @@ -118,12 +117,13 @@ impl Buf { #[inline] pub fn into_box(self) -> Box { - unsafe { mem::transmute(self.inner.into_boxed_slice()) } + let boxed = self.inner.into_boxed_slice(); + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Slice) } } #[inline] pub fn from_box(boxed: Box) -> Buf { - let inner: Box<[u8]> = unsafe { mem::transmute(boxed) }; + let inner = unsafe { Box::from_raw(Box::into_raw(boxed) as *mut [u8]) }; Buf { inner: inner.into_vec() } } @@ -140,7 +140,7 @@ impl Buf { impl Slice { fn from_u8_slice(s: &[u8]) -> &Slice { - unsafe { mem::transmute(s) } + unsafe { &*(s as *const [u8] as *const Slice) } } pub fn from_str(s: &str) -> &Slice { @@ -162,12 +162,12 @@ impl Slice { #[inline] pub fn into_box(&self) -> Box { let boxed: Box<[u8]> = self.inner.into(); - unsafe { mem::transmute(boxed) } + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Slice) } } pub fn empty_box() -> Box { let boxed: Box<[u8]> = Default::default(); - unsafe { mem::transmute(boxed) } + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Slice) } } #[inline] diff --git a/src/libstd/sys/unix/os_str.rs b/src/libstd/sys/unix/os_str.rs index e034938799866..5e25d92331a3c 100644 --- a/src/libstd/sys/unix/os_str.rs +++ b/src/libstd/sys/unix/os_str.rs @@ -14,7 +14,6 @@ use borrow::Cow; use fmt; use str; -use mem; use rc::Rc; use sync::Arc; use sys_common::{AsInner, IntoInner}; @@ -105,7 +104,7 @@ impl Buf { } pub fn as_slice(&self) -> &Slice { - unsafe { mem::transmute(&*self.inner) } + &*(&*self.inner as *const [u8] as *const Slice) } pub fn into_string(self) -> Result { @@ -118,12 +117,13 @@ impl Buf { #[inline] pub fn into_box(self) -> Box { - unsafe { mem::transmute(self.inner.into_boxed_slice()) } + let boxed = self.inner.into_boxed_slice(); + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Slice) } } #[inline] pub fn from_box(boxed: Box) -> Buf { - let inner: Box<[u8]> = unsafe { mem::transmute(boxed) }; + let inner = unsafe { Box::from_raw(Box::into_raw(boxed) as *mut [u8]) }; Buf { inner: inner.into_vec() } } @@ -140,7 +140,7 @@ impl Buf { impl Slice { fn from_u8_slice(s: &[u8]) -> &Slice { - unsafe { mem::transmute(s) } + unsafe { &*(s as *const [u8] as *const Slice) } } pub fn from_str(s: &str) -> &Slice { @@ -162,12 +162,12 @@ impl Slice { #[inline] pub fn into_box(&self) -> Box { let boxed: Box<[u8]> = self.inner.into(); - unsafe { mem::transmute(boxed) } + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Slice) } } pub fn empty_box() -> Box { let boxed: Box<[u8]> = Default::default(); - unsafe { mem::transmute(boxed) } + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Slice) } } #[inline] diff --git a/src/libstd/sys/wasm/os_str.rs b/src/libstd/sys/wasm/os_str.rs index 543c22ebe18a3..e48570a36e6d7 100644 --- a/src/libstd/sys/wasm/os_str.rs +++ b/src/libstd/sys/wasm/os_str.rs @@ -14,7 +14,6 @@ use borrow::Cow; use fmt; use str; -use mem; use rc::Rc; use sync::Arc; use sys_common::{AsInner, IntoInner}; @@ -105,7 +104,7 @@ impl Buf { } pub fn as_slice(&self) -> &Slice { - unsafe { mem::transmute(&*self.inner) } + &*(&*self.inner as *const [u8] as *const Slice) } pub fn into_string(self) -> Result { @@ -118,12 +117,13 @@ impl Buf { #[inline] pub fn into_box(self) -> Box { - unsafe { mem::transmute(self.inner.into_boxed_slice()) } + let boxed = self.inner.into_boxed_slice(); + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Slice) } } #[inline] pub fn from_box(boxed: Box) -> Buf { - let inner: Box<[u8]> = unsafe { mem::transmute(boxed) }; + let inner = unsafe { Box::from_raw(Box::into_raw(boxed) as *mut [u8]) }; Buf { inner: inner.into_vec() } } @@ -140,7 +140,7 @@ impl Buf { impl Slice { fn from_u8_slice(s: &[u8]) -> &Slice { - unsafe { mem::transmute(s) } + unsafe { &*(s as *const [u8] as *const Slice) } } pub fn from_str(s: &str) -> &Slice { @@ -162,12 +162,12 @@ impl Slice { #[inline] pub fn into_box(&self) -> Box { let boxed: Box<[u8]> = self.inner.into(); - unsafe { mem::transmute(boxed) } + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Slice) } } pub fn empty_box() -> Box { let boxed: Box<[u8]> = Default::default(); - unsafe { mem::transmute(boxed) } + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Slice) } } #[inline] diff --git a/src/libstd/sys/windows/os_str.rs b/src/libstd/sys/windows/os_str.rs index 414c9c5418e45..a449d58d74975 100644 --- a/src/libstd/sys/windows/os_str.rs +++ b/src/libstd/sys/windows/os_str.rs @@ -14,7 +14,6 @@ use borrow::Cow; use fmt; use sys_common::wtf8::{Wtf8, Wtf8Buf}; -use mem; use rc::Rc; use sync::Arc; use sys_common::{AsInner, IntoInner, FromInner}; @@ -90,7 +89,7 @@ impl Buf { } pub fn as_slice(&self) -> &Slice { - unsafe { mem::transmute(self.inner.as_slice()) } + &*(self.inner.as_slice() as *const Wtf8 as *const Slice) } pub fn into_string(self) -> Result { @@ -115,12 +114,13 @@ impl Buf { #[inline] pub fn into_box(self) -> Box { - unsafe { mem::transmute(self.inner.into_box()) } + let boxed = self.inner.into_box(); + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Slice) } } #[inline] pub fn from_box(boxed: Box) -> Buf { - let inner: Box = unsafe { mem::transmute(boxed) }; + let inner = unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Wtf8) }; Buf { inner: Wtf8Buf::from_box(inner) } } @@ -137,7 +137,7 @@ impl Buf { impl Slice { pub fn from_str(s: &str) -> &Slice { - unsafe { mem::transmute(Wtf8::from_str(s)) } + unsafe { &*(Wtf8::from_str(s) as *const Wtf8 as *const Slice) } } pub fn to_str(&self) -> Option<&str> { @@ -156,11 +156,13 @@ impl Slice { #[inline] pub fn into_box(&self) -> Box { - unsafe { mem::transmute(self.inner.into_box()) } + let boxed = self.inner.into_box(); + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Slice) } } pub fn empty_box() -> Box { - unsafe { mem::transmute(Wtf8::empty_box()) } + let boxed = Wtf8::empty_box(); + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut Slice) } } #[inline] diff --git a/src/libstd_unicode/lossy.rs b/src/libstd_unicode/lossy.rs index cc8e93308a527..592468ff7f40e 100644 --- a/src/libstd_unicode/lossy.rs +++ b/src/libstd_unicode/lossy.rs @@ -12,7 +12,6 @@ use core::str as core_str; use core::fmt; use core::fmt::Write; use char; -use core::mem; /// Lossy UTF-8 string. @@ -27,7 +26,7 @@ impl Utf8Lossy { } pub fn from_bytes(bytes: &[u8]) -> &Utf8Lossy { - unsafe { mem::transmute(bytes) } + unsafe { &*(bytes as *const [u8] as *const Utf8Lossy) } } pub fn chunks(&self) -> Utf8LossyChunksIter { From 071fe7ed948dbac8a3cb888483951c875ece31e2 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Sun, 7 Jan 2018 17:22:32 -0500 Subject: [PATCH 2/6] Add missing 'as' in casts --- src/bootstrap/cache.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/cache.rs b/src/bootstrap/cache.rs index f809504dac352..24f60c4c77689 100644 --- a/src/bootstrap/cache.rs +++ b/src/bootstrap/cache.rs @@ -114,7 +114,7 @@ impl Deref for Interned { fn deref(&self) -> &'static str { let l = INTERNER.strs.lock().unwrap(); let s: &str = l.get(*self).as_ref(); - unsafe { &*(s *const _) } + unsafe { &*(s as *const _) } } } @@ -123,7 +123,7 @@ impl Deref for Interned { fn deref(&self) -> &'static Path { let l = INTERNER.paths.lock().unwrap(); let p: &Path = l.get(*self).as_ref(); - unsafe { &*(p *const _) } + unsafe { &*(p as *const _) } } } @@ -137,7 +137,7 @@ impl AsRef for Interned { fn as_ref(&self) -> &'static Path { let l = INTERNER.strs.lock().unwrap(); let p: &Path = l.get(*self).as_ref(); - unsafe { &*(p *const _) } + unsafe { &*(p as *const _) } } } @@ -145,7 +145,7 @@ impl AsRef for Interned { fn as_ref(&self) -> &'static OsStr { let l = INTERNER.paths.lock().unwrap(); let s: &OsStr = l.get(*self).as_ref(); - unsafe { &*(s *const _) } + unsafe { &*(s as *const _) } } } @@ -153,7 +153,7 @@ impl AsRef for Interned { fn as_ref(&self) -> &'static OsStr { let l = INTERNER.strs.lock().unwrap(); let s: &OsStr = l.get(*self).as_ref(); - unsafe { &*(s *const _) } + unsafe { &*(s as *const _) } } } From d70bda89383b158cb26b8936fe9eb48753f5dbd4 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Sun, 7 Jan 2018 17:22:43 -0500 Subject: [PATCH 3/6] Swap Deref and AsRef impls for Interned --- src/bootstrap/cache.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/cache.rs b/src/bootstrap/cache.rs index 24f60c4c77689..114b92d17cdb1 100644 --- a/src/bootstrap/cache.rs +++ b/src/bootstrap/cache.rs @@ -121,15 +121,15 @@ impl Deref for Interned { impl Deref for Interned { type Target = Path; fn deref(&self) -> &'static Path { - let l = INTERNER.paths.lock().unwrap(); - let p: &Path = l.get(*self).as_ref(); - unsafe { &*(p as *const _) } + self.as_ref() } } impl AsRef for Interned { fn as_ref(&self) -> &'static Path { - &*self + let l = INTERNER.paths.lock().unwrap(); + let p: &Path = l.get(*self).as_ref(); + unsafe { &*(p as *const _) } } } From 5dfdaa8dc2f260e883ddf0c59a8cd84ce1cf2ce8 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Sun, 7 Jan 2018 17:38:29 -0500 Subject: [PATCH 4/6] Manually implement Deref for Interned Fixes lifetime errors that occur when using the AsRef implementation. --- src/bootstrap/cache.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/cache.rs b/src/bootstrap/cache.rs index 114b92d17cdb1..f9659fc25688a 100644 --- a/src/bootstrap/cache.rs +++ b/src/bootstrap/cache.rs @@ -121,7 +121,9 @@ impl Deref for Interned { impl Deref for Interned { type Target = Path; fn deref(&self) -> &'static Path { - self.as_ref() + let l = INTERNER.paths.lock().unwrap(); + let p: &Path = l.get(*self).as_ref(); + unsafe { &*(p as *const _) } } } From 284bdea4d6809d9d22ea6033542b8afb6f03581d Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Sun, 7 Jan 2018 18:20:42 -0500 Subject: [PATCH 5/6] Add missing `unsafe` blocks to raw pointer casts --- src/libstd/sys/redox/os_str.rs | 2 +- src/libstd/sys/unix/os_str.rs | 2 +- src/libstd/sys/wasm/os_str.rs | 2 +- src/libstd/sys/windows/os_str.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libstd/sys/redox/os_str.rs b/src/libstd/sys/redox/os_str.rs index 564eaf2bde20a..b00e2f56aa5e7 100644 --- a/src/libstd/sys/redox/os_str.rs +++ b/src/libstd/sys/redox/os_str.rs @@ -104,7 +104,7 @@ impl Buf { } pub fn as_slice(&self) -> &Slice { - &*(&*self.inner as *const [u8] as *const Slice) + unsafe { &*(&*self.inner as *const [u8] as *const Slice) } } pub fn into_string(self) -> Result { diff --git a/src/libstd/sys/unix/os_str.rs b/src/libstd/sys/unix/os_str.rs index 5e25d92331a3c..19a7d341d479e 100644 --- a/src/libstd/sys/unix/os_str.rs +++ b/src/libstd/sys/unix/os_str.rs @@ -104,7 +104,7 @@ impl Buf { } pub fn as_slice(&self) -> &Slice { - &*(&*self.inner as *const [u8] as *const Slice) + unsafe { &*(&*self.inner as *const [u8] as *const Slice) } } pub fn into_string(self) -> Result { diff --git a/src/libstd/sys/wasm/os_str.rs b/src/libstd/sys/wasm/os_str.rs index e48570a36e6d7..17833e12fd824 100644 --- a/src/libstd/sys/wasm/os_str.rs +++ b/src/libstd/sys/wasm/os_str.rs @@ -104,7 +104,7 @@ impl Buf { } pub fn as_slice(&self) -> &Slice { - &*(&*self.inner as *const [u8] as *const Slice) + unsafe { &*(&*self.inner as *const [u8] as *const Slice) } } pub fn into_string(self) -> Result { diff --git a/src/libstd/sys/windows/os_str.rs b/src/libstd/sys/windows/os_str.rs index a449d58d74975..baa20ff80490f 100644 --- a/src/libstd/sys/windows/os_str.rs +++ b/src/libstd/sys/windows/os_str.rs @@ -89,7 +89,7 @@ impl Buf { } pub fn as_slice(&self) -> &Slice { - &*(self.inner.as_slice() as *const Wtf8 as *const Slice) + unsafe { &*(self.inner.as_slice() as *const Wtf8 as *const Slice) } } pub fn into_string(self) -> Result { From 89373569476f98cd02068fffd77982b6b0a5f37d Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Sun, 7 Jan 2018 18:45:00 -0500 Subject: [PATCH 6/6] Fix mutability of array reference --- src/librustc_data_structures/blake2b.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_data_structures/blake2b.rs b/src/librustc_data_structures/blake2b.rs index 76ef301fb1789..abecf24a5614d 100644 --- a/src/librustc_data_structures/blake2b.rs +++ b/src/librustc_data_structures/blake2b.rs @@ -128,7 +128,7 @@ fn blake2b_compress(ctx: &mut Blake2bCtx, last: bool) { // before it's overwritten. let m: &mut [u64; 16] = unsafe { - &*(&mut ctx.b as *mut [u8; 128] as *mut [u64; 16]) + &mut *(&mut ctx.b as *mut [u8; 128] as *mut [u64; 16]) }; if cfg!(target_endian = "big") {