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


Express.js 5 Released With Greater Security
16/01/2025

Express.js 5 has been released, ten years after Express.js 4. The new release has dropped support for outdated versions of Node.js, addresses security concerns, and brings simplified maintenance.



DuckDB + Webassembly = WhatTheDuck
02/01/2025

Run DuckDB inside your browser thanks to Webassembly. When is that useful?


More News

espbook

 

Comments




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