Skip to content

Commit 981906e

Browse files
author
Lukas Markeffsky
committed
Revert "don't call align_offset during const eval, ever"
This reverts commit f3a577bfae376c0222e934911865ed14cddd1539.
1 parent eacc42a commit 981906e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

core/src/ptr/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,6 @@ pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
15911591
///
15921592
/// Any questions go to @nagisa.
15931593
#[lang = "align_offset"]
1594-
#[rustc_do_not_const_check] // hooked by const-eval
15951594
pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usize {
15961595
// FIXME(#75598): Direct use of these intrinsics improves codegen significantly at opt-level <=
15971596
// 1, where the method versions of these operations are not inlined.
@@ -1651,9 +1650,13 @@ pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usiz
16511650
inverse & m_minus_one
16521651
}
16531652

1654-
let addr = p.addr();
16551653
let stride = mem::size_of::<T>();
16561654

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).
1658+
let addr: usize = unsafe { mem::transmute(p) };
1659+
16571660
// SAFETY: `a` is a power-of-two, therefore non-zero.
16581661
let a_minus_one = unsafe { unchecked_sub(a, 1) };
16591662

0 commit comments

Comments
 (0)