From b5b8bee20307dce0736c4ecd985ce9c9bb86297f Mon Sep 17 00:00:00 2001 From: gerben Date: Mon, 10 Apr 2023 07:34:42 -0700 Subject: [PATCH 1/2] remove unsafe --- third_party/move/move-symbol-pool/src/pool.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/move/move-symbol-pool/src/pool.rs b/third_party/move/move-symbol-pool/src/pool.rs index ab7c67cfe50b2..e598df1c8e93d 100644 --- a/third_party/move/move-symbol-pool/src/pool.rs +++ b/third_party/move/move-symbol-pool/src/pool.rs @@ -62,8 +62,8 @@ impl Pool { /// Allocates a contiguous array of buckets on the heap. As strings are /// inserted into the pool, buckets in this array are filled with an entry. pub(crate) fn new() -> Self { - let vec = std::mem::ManuallyDrop::new(vec![0_usize; NB_BUCKETS]); - Self(unsafe { Box::from_raw(vec.as_ptr() as *mut [Bucket; NB_BUCKETS]) }) + const INIT: Bucket = None; + Self(Box::new([INIT; NB_BUCKETS])) } /// Computes the hash value of a string, which is used to determine both From 61dcf49f14ce4c9312d0ff138a415db4fb333763 Mon Sep 17 00:00:00 2001 From: gerben Date: Mon, 10 Apr 2023 07:37:18 -0700 Subject: [PATCH 2/2] add comment --- third_party/move/move-symbol-pool/src/pool.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/third_party/move/move-symbol-pool/src/pool.rs b/third_party/move/move-symbol-pool/src/pool.rs index e598df1c8e93d..0d9fb5b96286a 100644 --- a/third_party/move/move-symbol-pool/src/pool.rs +++ b/third_party/move/move-symbol-pool/src/pool.rs @@ -62,6 +62,8 @@ impl Pool { /// Allocates a contiguous array of buckets on the heap. As strings are /// inserted into the pool, buckets in this array are filled with an entry. pub(crate) fn new() -> Self { + // Using const INIT, works around the fact that [None; NB_BUCKETS] not being possible + // because Bucket is not Copy. const INIT: Bucket = None; Self(Box::new([INIT; NB_BUCKETS])) }