Skip to content

Commit ef2c2f2

Browse files
authored
Merge pull request #2090 from rust-lang/TC/remove-restriction-on-dereferencing-pointers-in-const
Remove restriction on dereferencing pointers in const
2 parents f9f1d2a + 0659e98 commit ef2c2f2

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/const_eval.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,23 @@ r[const-eval.const-expr.borrows]
203203
> See [issue #143129](https://github.com/rust-lang/rust/issues/143129) for more details.
204204
205205
r[const-eval.const-expr.deref]
206-
* The [dereference operator] except for raw pointers.
206+
* [Dereference expressions].
207+
208+
```rust,no_run
209+
# use core::cell::UnsafeCell;
210+
const _: u8 = unsafe {
211+
let x: *mut u8 = &raw mut *&mut 0;
212+
// ^^^^^^^
213+
// Dereference of mutable reference.
214+
*x = 1; // Dereference of mutable pointer.
215+
*(x as *const u8) // Dereference of constant pointer.
216+
};
217+
const _: u8 = unsafe {
218+
let x = &UnsafeCell::new(0);
219+
*x.get() = 1; // Mutation of interior mutable value.
220+
*x.get()
221+
};
222+
```
207223
208224
r[const-eval.const-expr.group]
209225

@@ -304,8 +320,8 @@ The types of a const function's parameters and return type are restricted to tho
304320
[constant expressions]: #constant-expressions
305321
[constants]: items/constant-items.md
306322
[Const parameters]: items/generics.md
307-
[dereference expression]: expressions/operator-expr.md#the-dereference-operator
308-
[dereference operator]: expressions/operator-expr.md#the-dereference-operator
323+
[dereference expression]: expr.deref
324+
[dereference expressions]: expr.deref
309325
[destructors]: destructors.md
310326
[enum discriminants]: items/enumerations.md#discriminants
311327
[expression statements]: statements.md#expression-statements

0 commit comments

Comments
 (0)