Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks
rustbot opened this issue Sep 26, 2024 · 2 comments
Open
3 tasks
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) F-const_refs_to_static `#![feature(const_refs_to_static)]` relnotes Marks issues that should be documented in the release notes of the next release. relnotes-tracking-issue Marks issues tracking what text to put in release notes. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. WG-const-eval Working group: Const evaluation
Milestone

Comments

@rustbot
Copy link
Collaborator

rustbot commented Sep 26, 2024

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

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc relnotes Marks issues that should be documented in the release notes of the next release. relnotes-tracking-issue Marks issues tracking what text to put in release notes. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 26, 2024
@rustbot rustbot added this to the 1.83.0 milestone Sep 26, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 26, 2024
@traviscross traviscross added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Sep 26, 2024
@saethlin saethlin added WG-const-eval Working group: Const evaluation A-const-eval Area: Constant evaluation (MIR interpretation) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. A-testsuite Area: The testsuite used to check the correctness of rustc labels Sep 27, 2024
@workingjubilee workingjubilee added the F-const_refs_to_static `#![feature(const_refs_to_static)]` label Sep 27, 2024
@RalfJung
Copy link
Member

RalfJung commented Sep 28, 2024

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
Copy link
Member

RalfJung commented Sep 28, 2024

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
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) F-const_refs_to_static `#![feature(const_refs_to_static)]` relnotes Marks issues that should be documented in the release notes of the next release. relnotes-tracking-issue Marks issues tracking what text to put in release notes. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. WG-const-eval Working group: Const evaluation
Projects
None yet
Development

No branches or pull requests

5 participants