Skip to content

Commit e037423

Browse files
committed
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.
2 parents a18dea9 + 0fbcb7b commit e037423

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/liballoc/arc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,8 @@ impl<'a, T: Clone> From<&'a [T]> for Arc<[T]> {
13771377
impl<'a> From<&'a str> for Arc<str> {
13781378
#[inline]
13791379
fn from(v: &str) -> Arc<str> {
1380-
unsafe { mem::transmute(<Arc<[u8]>>::from(v.as_bytes())) }
1380+
let arc = Arc::<[u8]>::from(v.as_bytes());
1381+
unsafe { Arc::from_raw(Arc::into_raw(arc) as *const str) }
13811382
}
13821383
}
13831384

src/liballoc/rc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,8 @@ impl<'a, T: Clone> From<&'a [T]> for Rc<[T]> {
10991099
impl<'a> From<&'a str> for Rc<str> {
11001100
#[inline]
11011101
fn from(v: &str) -> Rc<str> {
1102-
unsafe { mem::transmute(<Rc<[u8]>>::from(v.as_bytes())) }
1102+
let rc = Rc::<[u8]>::from(v.as_bytes());
1103+
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const str) }
11031104
}
11041105
}
11051106

0 commit comments

Comments
 (0)