From b8804107d2c8a9ab8ed4de4ed68ac58c117a97e5 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 24 Sep 2024 00:32:26 -0700 Subject: [PATCH 1/2] `fn mem::transmute`: Replace with sound `Arc::from_raw(Arc::into_raw(...) as *const _)` as `Arc` is not `#[repr(transparent)]`. --- src/disjoint_mut.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/disjoint_mut.rs b/src/disjoint_mut.rs index ea3e65f50..ba7111c63 100644 --- a/src/disjoint_mut.rs +++ b/src/disjoint_mut.rs @@ -1201,7 +1201,7 @@ impl FromIterator for DisjointMutArcSlice { // SAFETY: When `#[cfg(not(debug_assertions))]`, `DisjointMut` is `#[repr(transparent)]`, // containing only an `UnsafeCell`, which is also `#[repr(transparent)]`. - unsafe { mem::transmute::, Arc>>(arc_slice) } + unsafe { Arc::from_raw(Arc::into_raw(arc_slice) as *const DisjointMut<[_]>) } }; Self { inner } } From e063c90f500525d089e3d618675eb7dc7cb59037 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 24 Sep 2024 00:33:51 -0700 Subject: [PATCH 2/2] `fn DisjointMutArcSlice::from_iter`: Use inline `const {}` block to remove warning about dummy type. --- src/disjoint_mut.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/disjoint_mut.rs b/src/disjoint_mut.rs index ba7111c63..6af7985e5 100644 --- a/src/disjoint_mut.rs +++ b/src/disjoint_mut.rs @@ -1195,9 +1195,11 @@ impl FromIterator for DisjointMutArcSlice { let arc_slice = iter.into_iter().collect::>(); // Do our best to check that `DisjointMut` is in fact `#[repr(transparent)]`. - type A = Vec; // Some concrete sized type. - const _: () = assert!(mem::size_of::>() == mem::size_of::()); - const _: () = assert!(mem::align_of::>() == mem::align_of::()); + const { + type A = Vec; // Some concrete sized type. + assert!(mem::size_of::>() == mem::size_of::()); + assert!(mem::align_of::>() == mem::align_of::()); + } // SAFETY: When `#[cfg(not(debug_assertions))]`, `DisjointMut` is `#[repr(transparent)]`, // containing only an `UnsafeCell`, which is also `#[repr(transparent)]`.