-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
rust-lang/reference
#1590Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)B-experimentalBlocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).Blocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
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
ldm0, stepancheg, BennoLossin, CeleritasCelery, Qkessler and 4 morebjoernager
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)B-experimentalBlocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).Blocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.Status: It's hard to tell what's been done and what hasn't! Someone should do some investigation.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team