Skip to content

Tracking Issue for const_refs_to_cell #80384

Closed
rust-lang/reference
#1590
@oli-obk

Description

@oli-obk

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

Unresolved questions

  • The feature gate permits const BAR: AtomicUsize = ..; static FOO: &AtomicUsize = &BAR; and only prevents const FOO: &AtomicUsize = &BAR;. This decision was made because the implementation is simpler this way and we would already allow the static FOO case if BAR were a static itself.
    • This could be problematic, because LLVM ends up deduplicating some unnamed allocations like the one in static FOO
  • The soundness of this feature depends on the fact that if a StorageDead exists for a local, then for every assignment to the local, on each pass from that assignment to any return, there will be a StorageDead 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 a const FOO: &'static Cell<i32> which is unsound (and only caught by dynamic checks). The tracking issue for const heap is Tracking Issue for const_heap #79597

Implementation history

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: 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).B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: 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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions