const_heap feature can be used to leak mutable memory into final value of constant #129233
Labels
A-const-eval
Area: Constant evaluation (MIR interpretation)
F-const_heap
`#[feature(const_heap)]`
F-const_mut_refs
`#![feature(const_mut_refs)]`
F-core_intrinsics
Issue in the "core intrinsics" for internal usage only.
P-low
Low priority
requires-incomplete-features
Consider this code:
This code is problematic because when
BAR
is used multiple times in the program, it will always point to the same global allocation, violating the idea that consts behave as-if their initializer is inlined everywhere they are used. Furthermore, under our current interning strategy this allocation will end up being immutable in the runtime phase of the program, so writing it is UB, which could be quite surprising.We have a safety net in the interner that catches this problem, but the safety net has a big gaping hole around shared references with interior mutability, and can hence easily be circumvented:
The gaping hole in the safety net is needed due to #121610 and rust-lang/unsafe-code-guidelines#493; also see the description of #128543 for more context.
This seems like a pretty major blocker for the const_heap feature, unless we want to just declare this UB "ex machina".
Cc @rust-lang/wg-const-eval
(Not something to be discussed any time soon, I am filing this because tidy forced me to have an issue number for the ICE that ensues from this mutable-ref-escape-prevention-bypass.)
The text was updated successfully, but these errors were encountered: