Rust 1.83 expands const capabilities

The Rust Team has released Rust 1.83, an update to the memory-safe and thread-safe programming language that brings expanded capabilities for code running in const contexts. The Rust Team also announced that it is moving forward with the Rust 2024 edition, which introduces backwards-incompatible features such as gen blocks.

Developers with a previous edition of Rust installed via rustup can update to Rust 1.83 with the command rustup update stable.

With Rust 1.83, announced November 28, several large extensions are featured for const contexts. This refers to code the compiler evaluates at compile time: the initial value of const and static items, array lengths, enum discriminant values, const generic arguments, and functions callable from these contexts (const fn). Previously, const contexts except for the initializer expression of a static item were forbidden from referencing static items. This limitation has been lifted.

The Rust Team notes that reading the value of a mutable or interior mutable static still is not permitted in const contexts. And the final value of a constant may not reference mutable or interior mutable statics. These limitations ensure that constants are still “constant.” But a constant is permitted to evaluate to a raw pointer that points to a mutable or interior mutable static. Also, it is now permissible to use mutable references in const contexts. Mutable raw pointers and interior mutability also are now supported.

Improvements in the Rust 2024 edition, expected in Rust 1.85 in February 2025, are intended to make the language more consistent and ergonomic and boost safety while enabling long-awaited features such as gen blocks, let chains, and the never (!) type to be added to the language. The feature-complete Rust 2024 edition recently was merged to the release train for Rust 1.85. The Rust Team is asking users to migrate projects to the new edition, and provides instructions on doing so in the Rust blog. Rust 2024 edition will enter the beta channel on January 9, 2025.

Source

Yorum yapın