Skip to content

Commit

Permalink
Wording nits for const section
Browse files Browse the repository at this point in the history
Co-authored-by: Ralf Jung <[email protected]>
  • Loading branch information
BoxyUwU and RalfJung authored Nov 27, 2024
1 parent 3c8b478 commit fb4b0c7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions posts/2024-11-28-Rust-1.83.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you'd like to help us out by testing future releases, you might consider upda
This release includes several large extensions to what code running in const contexts can do. This refers to all code that the compiler has to evaluate at compile-time: the initial value of `const` and `static` items, array lengths, enum discriminant values, const generic arguments, and functions callable from such contexts (`const fn`).

**References to statics.**
So far, `const` items and `const fn` were forbidden from referencing `static items`.
So far, const contexts except for the initializer expression of a `static` item were forbidden from referencing `static` items.
This limitation has now been lifted:
```rust
static S: i32 = 25;
Expand All @@ -40,7 +40,9 @@ const C1: i32 = unsafe { S };
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:
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.

That said, a constant is permitted to evaluate to a raw pointer that points to a mutable or interior mutable static:
```rust
static mut S: i32 = 64;
const C: *mut i32 = &raw mut S;
Expand Down

0 comments on commit fb4b0c7

Please sign in to comment.