From 0fbcb7b873d140341fcfead9c47b1468617a596f Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Mon, 25 Dec 2017 17:04:45 -0500 Subject: [PATCH] Remove transmute in From<&str> impls for Arc/Rc --- src/liballoc/arc.rs | 3 ++- src/liballoc/rc.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 844b70835936f..185af8835d1e4 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -1377,7 +1377,8 @@ impl<'a, T: Clone> From<&'a [T]> for Arc<[T]> { impl<'a> From<&'a str> for Arc { #[inline] fn from(v: &str) -> Arc { - unsafe { mem::transmute(>::from(v.as_bytes())) } + let arc = Arc::<[u8]>::from(v.as_bytes()); + unsafe { Arc::from_raw(Arc::into_raw(arc) as *const str) } } } diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 358b5934b9231..59079f9ba76bc 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1099,7 +1099,8 @@ impl<'a, T: Clone> From<&'a [T]> for Rc<[T]> { impl<'a> From<&'a str> for Rc { #[inline] fn from(v: &str) -> Rc { - unsafe { mem::transmute(>::from(v.as_bytes())) } + let rc = Rc::<[u8]>::from(v.as_bytes()); + unsafe { Rc::from_raw(Rc::into_raw(rc) as *const str) } } }