What's New in Rust 1.95.0? Key Features and Updates
Rust 1.95.0 brings several powerful enhancements to the language, including a new macro for conditional compilation, improved pattern matching in match expressions, and a host of stabilized APIs. This release continues Rust's mission to empower developers to build reliable and efficient software. If you're using rustup, simply run rustup update stable to install it. For those eager to test upcoming features, switching to the beta or nightly channels is a great way to contribute feedback. Let's dive into the highlights of this release.
How do I update to Rust 1.95.0?
Updating to the latest stable release is straightforward with rustup. If you already have Rust installed via rustup, open your terminal and run rustup update stable. This command automatically fetches and installs version 1.95.0. If you don't have rustup yet, visit the official Rust website to get started. For those who want to help test future releases, you can set your toolchain to the beta channel with rustup default beta or the nightly channel with rustup default nightly. Please report any bugs you encounter—your feedback is invaluable for improving the language.

What is the cfg_select! macro and how does it simplify conditional compilation?
The cfg_select! macro, stabilized in Rust 1.95, acts as a compile-time match on configuration predicates. It serves a purpose similar to the popular cfg-if crate, but with its own syntax. The macro expands to the right-hand side of the first arm whose configuration condition evaluates to true. For example, you can write platform-specific functions or expressions without nesting #[cfg] attributes. Here's an illustration:
cfg_select! {
unix => { fn foo() { /* unix specific */ } }
target_pointer_width = "32" => { fn foo() { /* 32-bit fallback */ } }
_ => { fn foo() { /* default */ } }
}
This macro makes conditional code cleaner and more readable, especially in complex scenarios.
How do if-let guards in match expressions work in Rust 1.95?
Following the stabilization of let chains in Rust 1.88, version 1.95 extends that capability to match arms with if-let guards. You can now combine pattern matching with additional conditional checks directly inside a match expression. For instance:
match value {
Some(x) if let Ok(y) = compute(x) => {
// x and y are both available here
println!("{}, {}", x, y);
}
_ => {}
}
Note that the compiler currently does not consider patterns matched in if-let guards when evaluating exhaustiveness of the overall match, similar to regular if guards. This feature enhances expressiveness without compromising safety.
What are the notable stabilized APIs in Rust 1.95?
This release stabilizes several APIs, many focusing on safe conversions and atomic operations. Key additions include:
- MaybeUninit conversions:
MaybeUninit<[T; N]>now implementsFrom<[MaybeUninit<T>; N]>andAsRef/AsMutfor arrays and slices. - Cell array references:
Cell<[T; N]>andCell<[T]>gainAsRefimplementations. - bool TryFrom:
boolnow implementsTryFrom<{integer}>, allowing safe integer-to-boolean conversions. - Atomic updates:
AtomicPtr,AtomicBool, and atomic integer types (AtomicI,AtomicU) have newupdateandtry_updatemethods for atomic read-modify-write operations.
These additions improve ergonomics and safety when working with low-level data structures and concurrency.
What other new features and modules are introduced?
Rust 1.95 also introduces several other enhancements:
- New
core::rangemodule includingRangeInclusiveandRangeInclusiveIterfor more precise iteration control. core::hint::cold_path: a function to hint the compiler that a code path is unlikely, aiding branch prediction optimization.- Pointer methods:
<*const T>::as_ref_uncheckedand<*mut T>::as_{ref,mut}_uncheckedprovide unsafe ways to convert raw pointers to references. - Collection mutations:
Vec::push_mut,Vec::insert_mut,VecDeque::push_front_mut,VecDeque::push_back_mut,VecDeque::insert_mut, andLinkedList::push_front_mutallow in-place mutation of elements viaPin.
These additions make Rust's standard library more powerful for systems programming.
How can I help test future Rust releases?
If you'd like to contribute to Rust's development by testing upcoming features, you can easily switch your toolchain. Use rustup default beta to move to the beta channel, which contains features planned for the next stable release. For the latest experimental features, switch to the nightly channel with rustup default nightly. As you test, please report any bugs you encounter through the Rust issue tracker on GitHub. Your feedback helps the team identify and fix issues before they reach the stable release, making Rust more robust for everyone.