Long-wanted ability to upcast trait objects to trait objects of supertraits arrives in Rust 1.86, the latest update to the fast and safe programming language.

The Rust team has announced Rust 1.86, an update of the language that now features trait upcasting, or the ability to upcast trait objects.
Rust 1.86 was announced April 3. For users with a previous version of Rust, the update can be accessed via the rustup tool by running the command rustup update stable
.
With trait upcasting, if a trait has a supertrait, then developers can coerce a reference to a trait object to a reference to a trait object of the supertrait. The capability, which the Rust team described as a long-awaited feature, is stabilized in Rust 1.86. A supertrait is a trait that is required to be implemented for a type to implement a specific trait. Trait upcasting may be especially useful with the Any
trait, since it allows upcasting of trait objects to dyn Any
to call downcast methods of Any
without adding any trait methods or using external crates, the Rust team wrote.
Also in Rust 1.86, HashMap
and slices now support indexing multiple elements mutably. The borrow checker prevents simultaneous usage of references obtained from repeated calls to get_mut
methods, the team said. To safely support this pattern, the standard library now provides a get_disjoint_mut
helper on slices and HashMap
to retrieve mutable references to multiple elements simultaneously.
The compiler in Rust 1.86, meanwhile, now will insert debug assertions that a pointer is not null upon non-zero-sized reads and writes, and also when the pointer is reborrowed into a reference, according to the Rust team. Rust 1.86 also stabilizes the target_feature_11
feature, allowing safe functions to be marked with the #[target_feature]
attribute. Additionally in Rust 1.86, omitting the ABI in extern blocks and functions (e.g. extern {}
and extern fn
) now results in a warning (via the missing_abi
lint).
The Rust team also said the tier-2 target i586-pc-windows-msvc
will be removed in the next version of Rust, Rust 1.87.0.
Rust 1.86 also stabilizes the following APIs:
- {float}::next_down
- {float}::next_up
- <[_]>::get_disjoint_mut
- <[_]>::get_disjoint_unchecked_mut
- slice::GetDisjointMutError
- HashMap::get_disjoint_mut
- HashMap::get_disjoint_unchecked_mut
- NonZero::count_ones
- Vec::pop_if
- sync::Once::wait
- sync::Once::wait_force
- sync::OnceLock::wait
The following APIs are now stable in const contexts:
- hint::black_box
- io::Cursor::get_mut
- io::Cursor::set_position
- str::is_char_boundary
- str::split_at
- str::split_at_checked
- str::split_at_mut
- str::split_at_mut_checked
Rust 1.86 follows the February 20 release of Rust 1.85, which featured async closures. Rust 1.85 was followed on March 18 by a Rust 1.85.1 point release with fixes such as one for combined doctest compilation, which did not work as intended in the stable Rust 2024 edition.