From 85d9a06a62d73776b2fe7786e2d50e2833384331 Mon Sep 17 00:00:00 2001 From: bluss Date: Sat, 22 Dec 2018 14:25:16 +0100 Subject: [PATCH 1/3] FIX: Use repr(C) MaybeUninit after discussion with RalfJung We have a recommendation from the unsafe-wg (no rule yet), that repr(C) for unions should work this way, so that we can cast from the union type to one of its fields. --- src/maybe_uninit.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/maybe_uninit.rs b/src/maybe_uninit.rs index 71ec8f0..39c6366 100644 --- a/src/maybe_uninit.rs +++ b/src/maybe_uninit.rs @@ -7,6 +7,7 @@ use std::mem::ManuallyDrop; /// this wraps a value that can be wholly or partially uninitialized; /// it also has no drop regardless of the type of T. #[derive(Copy)] +#[repr(C)] // for cast from self ptr to value pub union MaybeUninit { empty: (), value: ManuallyDrop, From 06930d27ce8e292755754b1e09901fb36cd46919 Mon Sep 17 00:00:00 2001 From: bluss Date: Sat, 22 Dec 2018 19:59:32 +0100 Subject: [PATCH 2/3] FIX: Remove unused Copy/Clone for MaybeUninit --- src/maybe_uninit.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/maybe_uninit.rs b/src/maybe_uninit.rs index 39c6366..9ed1f6a 100644 --- a/src/maybe_uninit.rs +++ b/src/maybe_uninit.rs @@ -6,7 +6,6 @@ use std::mem::ManuallyDrop; /// A combination of ManuallyDrop and “maybe uninitialized”; /// this wraps a value that can be wholly or partially uninitialized; /// it also has no drop regardless of the type of T. -#[derive(Copy)] #[repr(C)] // for cast from self ptr to value pub union MaybeUninit { empty: (), @@ -14,11 +13,6 @@ pub union MaybeUninit { } // Why we don't use std's MaybeUninit on nightly? See the ptr method -impl Clone for MaybeUninit where T: Copy -{ - fn clone(&self) -> Self { *self } -} - impl MaybeUninit { /// Create a new MaybeUninit with uninitialized interior pub unsafe fn uninitialized() -> Self { From 21661facf8f5d65b4bd6701e48d218eb957314fa Mon Sep 17 00:00:00 2001 From: bluss Date: Sat, 22 Dec 2018 20:04:03 +0100 Subject: [PATCH 3/3] 0.4.10 --- Cargo.toml | 2 +- README.rst | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 61a61ce..4dd9697 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "arrayvec" -version = "0.4.9" +version = "0.4.10" authors = ["bluss"] license = "MIT/Apache-2.0" diff --git a/README.rst b/README.rst index 29d3a2f..4af5330 100644 --- a/README.rst +++ b/README.rst @@ -22,6 +22,11 @@ __ https://docs.rs/arrayvec Recent Changes (arrayvec) ------------------------- +- 0.4.10 + + - Use ``repr(C)`` in the ``union`` version that was introduced in 0.4.9, to + allay some soundness concerns. + - 0.4.9 - Use ``union`` in the implementation on when this is detected to be supported