Skip to content

Commit

Permalink
Remove unsafe (#7667)
Browse files Browse the repository at this point in the history
* remove unsafe

* add comment
  • Loading branch information
gerben-stavenga authored Apr 10, 2023
1 parent adf49ab commit 224192f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions third_party/move/move-symbol-pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ 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]) })
// 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]))
}

/// Computes the hash value of a string, which is used to determine both
Expand Down

0 comments on commit 224192f

Please sign in to comment.