Rust 1.83 Improves Const Context Code Handling
Thursday, 12 December 2024

Rust 1.83 has been released with improvements to the handling of code running in const contexts.

Rust is popular for situations including being embedded in other languages, writing programs with specific space and time requirements, and writing low-level code.

rust foundation logo

This release has a number of large extensions to what code running in const contexts can do. This covers a substantial amount of code as it 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).

The improvements start with a lifting of the limitation on referencing static items. Until now, const contexts except for the initializer expression of a static item were forbidden from referencing static items. This limitation has now been lifted.

You still aren't allowed to read the value of a mutable or interior mutable static in const contexts, nor can the final value of a constant reference mutable or interior mutable statics. However, you can now use mutable references in const contexts. The limitations have been kept to 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.

Alongside the improvements to const contexts, this release also ships with new functions that are now stable in const contexts, and a long list of stabilized APIs. The Rust team says the changes:

"unblock an entire new category of code to be executed inside const contexts, and we are excited to see how the Rust ecosystem will make use of this!"

Version 1.83 of Rust is available now.

rust foundation logo

More Information

Rust Foundation Website

Related Articles

Rust 1.82 Improves Apple Support

RustConf Keynotes Announced

Is Rust Safe?

Rust Foundation Announces Safety-Critical Consortium

Rust 1.72 Stabilizes APIs

Rust Foundation Establishes Security Team

Amazon AWS Invests In Rust

Google Supports Rust For Android OS Development

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


$20,000 If You Can Make This Rust Program As Fast As C
19/05/2025

This is a storm in a Rust bucket. Prosimo decided that a good test of Rust was to convert the existing dav1d decoder from C to Rust. Everything seems to have gone well, but the Rust version is still 5 [ ... ]



LiteCLI SQLite Client Is Now Powered By LLM
19/05/2025

LiteCLI, a very handy SQLite client for the CLI diehards, is upgraded by getting a LLM feature that helps you write SQL.


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info