Remove restriction on dereferencing pointers in const #2090
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.
We had said that the dereference operator could not be used with raw pointers in a constant expression. However, that restriction has been lifted. First, in Rust 1.58, we stabilized
const_raw_ptr_deref.rust-lang/rust#89551
This allowed for dereferencing immutable raw pointers in a constant expression. Then, in Rust 1.83, we stabilized
const_mut_refsandconst_refs_to_cell.rust-lang/rust#129195
That allowed for:
&muttypes.&mutand*mutvalues.&Tand*const Tvalues whereTcontains interior mutability.&mutand*mutvalues (both for reads and writes).Let's remove the stated restriction on dereferencing raw pointers in a constant expression and add examples.
cc @ehuss @RalfJung
I noticed this when double-checking that we didn't need to do anything for:
cc @rust-lang/fls