Skip to content

Commit 68605a2

Browse files
Use slice::from_raw_parts instead of mem::transmute
Layout compatibility guarantees for `T` do not extend to types containing `T` (like `&[T]`), so use `from_raw_parts` instead of `mem::transmute`.
1 parent 3ff4ad0 commit 68605a2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/join.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,14 @@ impl<'me, Tuple: Ord> JoinInput<'me, (Tuple, ())> for &'me Relation<Tuple> {
187187
assert_eq!(mem::align_of::<(Tuple, ())>(), mem::align_of::<Tuple>());
188188

189189
// SAFETY: https://rust-lang.github.io/unsafe-code-guidelines/layout/structs-and-tuples.html#structs-with-1-zst-fields
190-
// guarantees that `T` is layout compatible with `(T, ())`, since `()` is a 1-ZST.
190+
// guarantees that `T` is layout compatible with `(T, ())`, since `()` is a 1-ZST. We use
191+
// `slice::from_raw_parts` because the layout compatibility guarantee does not extend to
192+
// containers like `&[T]`.
191193
let elements: &'me [Tuple] = self.elements.as_slice();
192-
let elements: &'me [(Tuple, ())] = unsafe { std::mem::transmute(elements) };
194+
let len = elements.len();
195+
196+
let elements: &'me [(Tuple, ())] =
197+
unsafe { std::slice::from_raw_parts(elements.as_ptr() as *const _, len) };
193198

194199
f(elements)
195200
}

0 commit comments

Comments
 (0)