From e90d15b247bdaf12a6d51f492bf94d2e0064d177 Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 16 Nov 2022 15:08:35 +0100 Subject: [PATCH] Update comment on pointer-to-usize transmute Co-authored-by: Ralf Jung --- library/core/src/ptr/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 9283b81a84e..73923753a30 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1652,9 +1652,10 @@ pub(crate) const unsafe fn align_offset(p: *const T, a: usize) -> usiz let stride = mem::size_of::(); - // SAFETY: At runtime, transmuting a pointer to `usize` is always safe, because they have the - // same layout. During const eval, we hook this function to ensure that the pointer always has - // an address (only the standard library can do this). + // SAFETY: This is just an inlined `p.addr()` (which is not + // a `const fn` so we cannot call it). + // During const eval, we hook this function to ensure that the pointer never + // has provenance, making this sound. let addr: usize = unsafe { mem::transmute(p) }; // SAFETY: `a` is a power-of-two, therefore non-zero.