Stabilize &mut (and *mut) as well as &Cell (and *const Cell) in const#129195
Merged
bors merged 4 commits intorust-lang:masterfrom Sep 15, 2024
Merged
Stabilize &mut (and *mut) as well as &Cell (and *const Cell) in const#129195bors merged 4 commits intorust-lang:masterfrom
&mut (and *mut) as well as &Cell (and *const Cell) in const#129195bors merged 4 commits intorust-lang:masterfrom
Conversation
Collaborator
Collaborator
|
Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
&mut (and *mut) in const
This comment has been minimized.
This comment has been minimized.
2cd942d to
8cdd976
Compare
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Aug 17, 2024
…inter, r=<try> make writes_through_immutable_pointer a hard error This turns the lint added in rust-lang#118324 into a hard error. This has been reported in cargo's future-compat reports since Rust 1.76 (released in February). Given that const_mut_refs is still unstable, it should be impossible to even hit this error on stable: we did accidentally stabilize some functions that can cause this error, but that got reverted in rust-lang#117905. Still, let's do a crater run just to be sure. Given that this should only affect unstable code, I don't think it needs an FCP, but let's Cc `@rust-lang/lang` anyway -- any objection to making this unambiguous UB into a hard error during const-eval? This can be viewed as part of rust-lang#129195 which is already nominated for discussion.
This comment has been minimized.
This comment has been minimized.
8cdd976 to
5caada9
Compare
This comment has been minimized.
This comment has been minimized.
5caada9 to
a536a20
Compare
8 tasks
This comment has been minimized.
This comment has been minimized.
a536a20 to
7ab0df0
Compare
This comment has been minimized.
This comment has been minimized.
7ab0df0 to
8089358
Compare
5 tasks
806950e to
49316f8
Compare
Member
Author
|
@bors r=fee1-dead |
Collaborator
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 15, 2024
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#129195 (Stabilize `&mut` (and `*mut`) as well as `&Cell` (and `*const Cell`) in const) - rust-lang#130118 (move Option::unwrap_unchecked into const_option feature gate) - rust-lang#130295 (Fix target-cpu fpu features on Armv8-R.) - rust-lang#130371 (Correctly account for niche-optimized tags in rustc_transmute) - rust-lang#130381 (library: Compute Rust exception class from its string repr) r? `@ghost` `@rustbot` modify labels: rollup
This was referenced Sep 19, 2024
60 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This stabilizes
const_mut_refsandconst_refs_to_cell. That allows a bunch of new things in const contexts:&muttypes&mutand*mutvalues&Tand*const Tvalues whereTcontains interior mutability&mutand*mutvalues (both for reads and writes)The same rules as at runtime apply: mutating immutable data is UB. This includes mutation through pointers derived from shared references; the following is diagnosed with a hard error:
The main limitation that is enforced is that the final value of a const (or non-
mutstatic) may not contain&mutvalues nor interior mutable&values. This is necessary because the memory those references point to becomes read-only when the constant is done computing, so (interior) mutable references to such memory would be pretty dangerous. We take a multi-layered approach here to ensuring no mutable references escape the initializer expression:&mutor interior-mutable&we error out.unionor raw pointers, so there is a second dynamic check where if the final value of the const contains any pointer that was not derived from a shared reference, we complain. This is currently a future-compat lint, but will become an ICE in const-eval interning: accept interior mutable pointers in final value #128543. On the off-chance that it's actually possible to trigger this lint on stable, I'd prefer if we could make it an ICE before stabilizing const_mut_refs, but it's not a hard blocker. This part of the "safety net" is only active for mutable references since with shared references, it has false positives.Altogether this should prevent people from leaking (interior) mutable references out of the const initializer.
While updating the tests I learned that surprisingly, this code gets rejected:
The analysis that rejects destructors in
constis very conservative when it sees an&mutbeing created tox, and then considersxto be always live. See here for a longer explanation.const_precise_live_dropswill solve this, so I consider this problem to be tracked by #73255.Cc @rust-lang/wg-const-eval @rust-lang/lang
Cc #57349
Cc #80384