Skip to content

Commit e90d15b

Browse files
lukas-codeRalfJung
authored and
Lukas Markeffsky
committed
Update comment on pointer-to-usize transmute
Co-authored-by: Ralf Jung <[email protected]>
1 parent 3d7e9c4 commit e90d15b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

library/core/src/ptr/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1652,9 +1652,10 @@ pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usiz
16521652

16531653
let stride = mem::size_of::<T>();
16541654

1655-
// SAFETY: At runtime, transmuting a pointer to `usize` is always safe, because they have the
1656-
// same layout. During const eval, we hook this function to ensure that the pointer always has
1657-
// an address (only the standard library can do this).
1655+
// SAFETY: This is just an inlined `p.addr()` (which is not
1656+
// a `const fn` so we cannot call it).
1657+
// During const eval, we hook this function to ensure that the pointer never
1658+
// has provenance, making this sound.
16581659
let addr: usize = unsafe { mem::transmute(p) };
16591660

16601661
// SAFETY: `a` is a power-of-two, therefore non-zero.

0 commit comments

Comments
 (0)