Closed
Description
This is a tracking issue for taking references to values of types that (may) contain UnsafeCell
within const contexts.
The feature gate for the issue is #![feature(const_refs_to_cell)]
.
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
- Implement the RFC (Allow references to interior mutable data behind a feature gate #80418)
- Adjust documentation: const_eval: update for const_mut_refs and const_refs_to_cell stabilization reference#1590
- Stabilization PR: Stabilize
&mut
(and*mut
) as well as&Cell
(and*const Cell
) in const #129195
Unresolved questions
- The feature gate permits
const BAR: AtomicUsize = ..; static FOO: &AtomicUsize = &BAR;
and only preventsconst FOO: &AtomicUsize = &BAR;
. This decision was made because the implementation is simpler this way and we would already allow thestatic FOO
case ifBAR
were a static itself.- This could be problematic, because LLVM ends up deduplicating some unnamed allocations like the one in
static FOO
- This could be problematic, because LLVM ends up deduplicating some unnamed allocations like the one in
The soundness of this feature depends on the fact that if aStorageDead
exists for a local, then for every assignment to the local, on each pass from that assignment to anyreturn
, there will be aStorageDead
for this local.- Once we get heap allocations in constants, it would be possible for users to write a
const fn foo() -> &'static Cell<i32>
, which could then be used to initialize aconst FOO: &'static Cell<i32>
which is unsound (and only caught by dynamic checks). The tracking issue for const heap is Tracking Issue forconst_heap
#79597
Implementation history
Metadata
Metadata
Assignees
Labels
Area: Constant evaluation, covers all const contexts (static, const fn, ...)Blocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).Blocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFCStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the language team, which will review and decide on the PR/issue.