Auto merge of #47004 - nvzqz:rc-conversions, r=bluss,kennytm

Remove transmute in From<&str> impls for Arc/Rc

Performs conversion via raw pointer casts.
This commit is contained in:
bors 2017-12-31 10:36:28 +00:00
commit e03742368f
2 changed files with 4 additions and 2 deletions

View File

@ -1377,7 +1377,8 @@ impl<'a, T: Clone> From<&'a [T]> for Arc<[T]> {
impl<'a> From<&'a str> for Arc<str> {
#[inline]
fn from(v: &str) -> Arc<str> {
unsafe { mem::transmute(<Arc<[u8]>>::from(v.as_bytes())) }
let arc = Arc::<[u8]>::from(v.as_bytes());
unsafe { Arc::from_raw(Arc::into_raw(arc) as *const str) }
}
}

View File

@ -1099,7 +1099,8 @@ impl<'a, T: Clone> From<&'a [T]> for Rc<[T]> {
impl<'a> From<&'a str> for Rc<str> {
#[inline]
fn from(v: &str) -> Rc<str> {
unsafe { mem::transmute(<Rc<[u8]>>::from(v.as_bytes())) }
let rc = Rc::<[u8]>::from(v.as_bytes());
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const str) }
}
}