Skip to content

Commit f2dfe16

Browse files
author
Lukas Markeffsky
committed
don't call align_offset during const eval, ever
1 parent 4743fca commit f2dfe16

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

core/src/ptr/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,9 +1590,8 @@ pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
15901590
/// than trying to adapt this to accommodate that change.
15911591
///
15921592
/// Any questions go to @nagisa.
1593-
// #[cfg(not(bootstrap))] -- Calling this function in a const context from the bootstrap
1594-
// compiler will always cause an error.
15951593
#[lang = "align_offset"]
1594+
#[rustc_do_not_const_check] // hooked by const-eval
15961595
pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usize {
15971596
// FIXME(#75598): Direct use of these intrinsics improves codegen significantly at opt-level <=
15981597
// 1, where the method versions of these operations are not inlined.
@@ -1652,13 +1651,9 @@ pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usiz
16521651
inverse & m_minus_one
16531652
}
16541653

1654+
let addr = p.addr();
16551655
let stride = mem::size_of::<T>();
16561656

1657-
// SAFETY: At runtime transmuting a pointer to `usize` is always safe, because they have the
1658-
// same layout. During const eval we hook this function to ensure that the pointer always has
1659-
// an address (only the standard library can do this).
1660-
let addr = unsafe { mem::transmute(p) };
1661-
16621657
// SAFETY: `a` is a power-of-two, therefore non-zero.
16631658
let a_minus_one = unsafe { unchecked_sub(a, 1) };
16641659

0 commit comments

Comments
 (0)