What Is New in Rust 1.83
| Category | Highlights |
|---|---|
| New Features | Const contexts can now reference immutable statics, use mutable references, mutable raw pointers, and interior mutability; many std functions are now const. |
| Improvements | Stabilized a large set of standard library APIs for const usage, expanding compile-time computation possibilities. |
Can I reference static items inside const contexts in Rust 1.83?
Yes, Rust 1.83 lifts the previous restriction and allows consts to take references to immutable statics.
In practice this means you can write:
static S: i32 = 25;
const C: &i32 = &S;
Watch out for mutable statics: they are still prohibited from being read in const contexts, preserving constant semantics.
Is it possible to use mutable references in const functions starting with Rust 1.83?
Yes, mutable references are now permitted inside const fn bodies.
This matters if you need to perform in-place updates during compile-time evaluation. Example:
const fn inc(x: &mut i32) {
*x += 1;
}
const C: i32 = {
let mut c = 41;
inc(&mut c);
c
};
Note that mutable references cannot escape the const computation; they cannot appear in the final constant value.
Which standard library APIs became const-stable in Rust 1.83?
A broad set of std functions, especially in core::mem, core::ptr, and collection helpers, are now const-stable.
In practice you can call these functions inside const blocks without nightly features. For example, you can use core::mem::size_of or core::ptr::read directly in a const context.
Most teams will see immediate benefit when refactoring compile-time calculations, as the need for work-arounds disappears.
Frequently Asked Questions
How do I upgrade to Rust 1.83?
Run rustup update stable to download and install the new compiler.
Do existing const functions need changes after the new const capabilities?
Most existing const fn will continue to work unchanged; you can now add mutable references without breaking existing code.
Can I read a mutable static in a const expression?
No, reading mutable or interior mutable statics is still prohibited in const contexts.
Is it safe to return a raw pointer to a mutable static from a const?
Yes, a const can evaluate to a raw pointer pointing to a mutable static, but you cannot dereference it at compile time.
Which Cargo command shows the new const-stable APIs?
Use cargo doc --open to view the updated const stability annotations in the standard library documentation.
Will using mutable references in const affect runtime performance?
No, the mutable operations are performed at compile time, so runtime performance remains unchanged.