From aadfd810f62e2e07440672cc20a0540c9904d69b Mon Sep 17 00:00:00 2001
From: James Wainwright <james.wainwright@lowrisc.org>
Date: Tue, 25 Mar 2025 21:44:54 +0000
Subject: [PATCH] Swap usize -> ptr transmute for strict_pov API

Removes some unsafety and reduces the number of `usize` -> `ptr`
transmutes which might be helpful for CHERI-like targets in the future.
---
 library/alloc/src/raw_vec/mod.rs | 3 +--
 library/alloctests/lib.rs        | 1 +
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/library/alloc/src/raw_vec/mod.rs b/library/alloc/src/raw_vec/mod.rs
index 83facd9d932..a989e5b55b3 100644
--- a/library/alloc/src/raw_vec/mod.rs
+++ b/library/alloc/src/raw_vec/mod.rs
@@ -410,8 +410,7 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawVec<T, A> {
 impl<A: Allocator> RawVecInner<A> {
     #[inline]
     const fn new_in(alloc: A, align: Alignment) -> Self {
-        // SAFETY: `Alignment` is non-zero.
-        let ptr = unsafe { core::mem::transmute(align) };
+        let ptr = Unique::from_non_null(NonNull::without_provenance(align.as_nonzero()));
         // `cap: 0` means "unallocated". zero-sized types are ignored.
         Self { ptr, cap: ZERO_CAP, alloc }
     }
diff --git a/library/alloctests/lib.rs b/library/alloctests/lib.rs
index 3241b4b0045..56e60ed4c84 100644
--- a/library/alloctests/lib.rs
+++ b/library/alloctests/lib.rs
@@ -28,6 +28,7 @@
 #![feature(iter_next_chunk)]
 #![feature(maybe_uninit_slice)]
 #![feature(maybe_uninit_uninit_array_transpose)]
+#![feature(nonnull_provenance)]
 #![feature(ptr_alignment_type)]
 #![feature(ptr_internals)]
 #![feature(sized_type_properties)]