about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJames Wainwright <james.wainwright@lowrisc.org>2025-03-25 21:44:54 +0000
committerJames Wainwright <james.wainwright@lowrisc.org>2025-03-26 21:41:11 +0000
commitaadfd810f62e2e07440672cc20a0540c9904d69b (patch)
tree92b2c41db7be2267fa3e052f1965ba3020ed849b
parent78e962139020df03174f03da6af91acc5cbb37e3 (diff)
downloadrust-aadfd810f62e2e07440672cc20a0540c9904d69b.tar.gz
rust-aadfd810f62e2e07440672cc20a0540c9904d69b.zip
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.
-rw-r--r--library/alloc/src/raw_vec/mod.rs3
-rw-r--r--library/alloctests/lib.rs1
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)]