The Rust programming language has introduced an exciting new feature in its latest update, Rust 1.86, which was released on April 3. This update includes the long-awaited addition of trait upcasting, a capability that allows developers to upcast trait objects. This feature makes it easier to work with trait hierarchies, especially when dealing with supertraits. A supertrait is a trait that must be implemented by a type in order for it to implement another trait. With trait upcasting, developers can now coerce a reference to a trait object into a reference to a trait object of its supertrait, enabling more flexible and cleaner code.
In addition to trait upcasting, Rust 1.86 brings several other improvements and new features. One of the major enhancements is the ability to index multiple elements mutably in both HashMap
and slices. This feature addresses a common challenge where the borrow checker prevents simultaneous use of references obtained from multiple calls to the get_mut
method. To handle this safely, the standard library now includes a get_disjoint_mut
helper function that allows developers to retrieve mutable references to multiple elements simultaneously, enhancing the usability of Rust’s collection types.
The Rust 1.86 update also improves the compiler with new debug assertions to ensure safety when handling pointers. Specifically, the compiler will now insert checks to verify that a pointer is not null during non-zero-sized reads and writes, as well as when the pointer is reborrowed into a reference. This extra layer of safety helps developers catch potential issues during development, improving the overall reliability of Rust programs. Additionally, the update stabilizes the target_feature_11
feature, which allows developers to mark safe functions with the #[target_feature]
attribute, further improving the language’s capabilities in low-level programming.
Furthermore, Rust 1.86 introduces a warning system for missing ABIs in extern blocks and functions. When the ABI is omitted in extern declarations (e.g., extern {}
or extern fn
), a warning is now issued through the missing_abi
lint. This change helps ensure that Rust developers are aware of potential issues in their foreign function interface (FFI) code. The Rust team also announced that the tier-2 target i586-pc-windows-msvc
will be removed in Rust 1.87.0, signaling the ongoing evolution of the language and its focus on supporting the most commonly used platforms.