Open
Description
See the following snippet: (currently ICEs)
#![feature(core_intrinsics)]
#![feature(const_heap)]
use std::mem::{align_of, size_of};
use std::intrinsics;
struct SelfReferential {
me: *const SelfReferential,
}
const Y: &'static SelfReferential = unsafe {
let size = size_of::<SelfReferential>();
let align = align_of::<SelfReferential>();
let ptr_raw = intrinsics::const_allocate(size, align);
let ptr = ptr_raw as *mut SelfReferential;
let me_addr = &raw mut (*ptr).me;
*me_addr = ptr;
intrinsics::const_make_global(ptr_raw, size, align);
&*ptr
};
fn main() {}
me
's provenance says it wasn't derived from an immutable reference. We can't really change that because it can't be mutated after we callconst_make_global
.- The fact above hits "accepted a mutable pointer that should not have accepted" at
rust/compiler/rustc_const_eval/src/interpret/intern.rs
Lines 247 to 265 in 040e2f8
- We can check if
alloc_id
has kindHeap { was_made_immut: true }
and skip the error that way. intern_shallow
will keep returning alloc2 adding to our todo list being weird left and right. I added a.filter
inrust/compiler/rustc_const_eval/src/interpret/intern.rs
Lines 311 to 312 in 040e2f8
just_interned
.- Apparently that wasn't enough and rustc hits an infinite loop at some point. The stack trace isn't helpful enough and I didn't have enough time to find a way to debug the stack overflow.
Originally posted by @fee1-dead in #143595 (comment)