Internet

Rust adds diagnostic attributes for compiler messages


Rust 1.78, just released as the latest version of the popular, memory-safe programming language, adds backing for a #[diagnostic] attribute namespace to influence compiler messages.

These messages are treated as hints that the compiler is not required to use, the Rust team said. Also it is not an error to provide a diagnostic that the compiler does not recognize. The feature is designed to allow source code to provide diagnostics even when they are not supported by all compilers.

Announced May 2, Rust 1.78 can be installed via rustup:

$ rustup update stable

Another feature in Rust 1.78 pertains to asserting unsafe preconditions. The Rust standard library has a number of assertions for preconditions of unsafe functions, but historically they have been enabled only in #[cfg(debug_assertions)] builds of the library to avoid affecting release performance. Since the library usually is compiled and distributed in release mode, most Rust developers were not executing these checks.

With Rust 1.78, the condition for these assertions is delayed until code generation, so they will be checked depending on the user’s setting for debug assertions, enabled by default in debug and test builds. This change will help catch undefined behavior in code, the Rust team said. However, the details of how much is checked generally are not stable.

Deterministic realignment also is featured in Rust 1.78. The standard library has functions that change alignment of pointers and slices, but they previously had caveats that made them difficult to rely on in practice. These caveats mostly existed as a hedge against const evaluation, but they were only stable for non-const use. Now, they are promised to have consistent runtime behavior according to actual inputs.

Rust 1.78 also stabilizes a number of APIs, raises its minimum requirement to Windows 10 for targets such as x_86-pc-windows-msvc, and upgrades its bundled LLVM to LLVM 18.

Rust 1.78 follows the March 21 release of Rust 1.77, which featured support for C-string literals. Two subsequent point releases also were made, Rust 1.77.1, which disabled new Cargo behavior on Windows for targets using MSVC (Microsoft C and C++), and Rust 1.77.2, which included a vulnerability fix.

Copyright © 2024 IDG Communications, Inc.



READ SOURCE

Business Asia
the authorBusiness Asia

Leave a Reply