From 296575f0db504314dbc53d6e75c7df7fb83a6b7b Mon Sep 17 00:00:00 2001 From: Tayfun Bocek Date: Wed, 28 Feb 2024 15:56:53 +0300 Subject: [PATCH] More in depth safety explanation. --- src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 41f8707..8b619d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -280,12 +280,16 @@ macro_rules! _concat_slices { // SAFETY: Transmuting an array of initialized MaybeUninit's is completely safe, where // all of its items are initialized. + // As per the documentation of `core::mem::MaybeUninit`: "https://doc.rust-lang.org/core/mem/union.MaybeUninit.html#layout-1" + // This means it is safe to transmute as the slices must be the same type in order to + // be placed in the array. In such case the user does provide slices with different + // types, it would give a compile error before even reaching the unsafe block. // // The only way it would be UB is where `base` and the array length (`LEN`) is // different, as it would end up assuming the non-initialized items do exist. // Mentioned case is handled above as a comp time panic above. // - // See https://doc.rust-lang.org/core/mem/union.MaybeUninit.html#initializing-an-array-element-by-element + // See for more information: https://doc.rust-lang.org/core/mem/union.MaybeUninit.html#initializing-an-array-element-by-element unsafe {core::mem::transmute(arr)} }; &ARR