Skip to content

Tracking issue for release notes of #129759: Stabilize const_refs_to_static #130901

Closed
@rustbot

Description

@rustbot
Collaborator

This issue tracks the release notes text for #129759.

Steps

  • Proposed text is drafted by PR author (or team) making the noteworthy change.
    Issue is nominated for release team review of clarity for wider audience.
    Release team includes text in release notes/blog posts.

Release notes text

The responsible team for the underlying change should edit this section to replace the automatically generated link with a succinct description of what changed, drawing upon text proposed by the author (either in discussion or through direct editing).

# Language
- [Allow creating references to statics in `const` initializers.](https://github.com/rust-lang/rust/pull/129759)

Tip

Use the previous releases categories to help choose which one(s) to use.
The category will be de-duplicated with all the other ones by the release team.

More than one section can be included if needed.

Release blog section

If the change is notable enough for inclusion in the blog post, the responsible team should add content to this section.
Otherwise leave it empty.

cc @dingxiangfei2009, @RalfJung -- origin issue/PR authors and assignees for starting to draft text

Activity

added
A-testsuiteArea: The testsuite used to check the correctness of rustc
relnotesMarks issues that should be documented in the release notes of the next release.
relnotes-tracking-issueMarks issues tracking what text to put in release notes.
T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Sep 26, 2024
added this to the 1.83.0 milestone on Sep 26, 2024
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Sep 26, 2024
added
WG-const-evalWorking group: Const evaluation
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
A-testsuiteArea: The testsuite used to check the correctness of rustc
on Sep 27, 2024
RalfJung

RalfJung commented on Sep 28, 2024

@RalfJung
Member

We'll have a big section on the const_mut_ref stuff (#130362), not sure if we want a dedicated section for this or just make it "more cool const stuff".

RalfJung

RalfJung commented on Sep 28, 2024

@RalfJung
Member

Here's a draft of what IMO should be put in one overarching section with the text from #130362.

References to statics.
So far, const items and const fn were forbidden from referencing static items.
This limitation has now been lifted:

static S: i32 = 25;
const C: &i32 = &S;

Note, however, that reading the value of a mutable or interior mutable static is still not permitted in const contexts.
Furthermore, the final value of a constant may not reference any mutable or interior mutable statics:

static mut S: i32 = 0;

const C1: i32 = unsafe { S };
// error: constant accesses mutable global memory

const C2: &i32 = unsafe { &S };
// error: encountered reference to mutable memory in `const`

These limitations ensure that constants are still "constant": the value they evaluate to, and their meaning as a pattern (which can involve dereferencing references), will be the same throughout the entire program execution.

However, a constant is permitted to evaluate to a raw pointer that points to a mutable or interior mutable static:

static mut S: i32 = 64;
const C: *mut i32 = &raw mut S;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)F-const_refs_to_static`#![feature(const_refs_to_static)]`T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamWG-const-evalWorking group: Const evaluationrelnotesMarks issues that should be documented in the release notes of the next release.relnotes-tracking-issueMarks issues tracking what text to put in release notes.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @RalfJung@traviscross@saethlin@workingjubilee@rustbot

        Issue actions

          Tracking issue for release notes of #129759: Stabilize `const_refs_to_static` · Issue #130901 · rust-lang/rust