Rust 1.95.0: New Macro, Match Guards, and API Stabilizations
Welcome to the latest stable release of Rust, version 1.95.0! This update brings a new compile-time macro, enhanced pattern matching in match expressions, and a fresh set of stabilized APIs. Whether you're a systems programmer or a hobbyist, these additions aim to improve code clarity and safety. Let's dive into the key changes with a Q&A format.
How do I update to Rust 1.95.0?
If you already have Rust installed via rustup, simply run the following command in your terminal:

$ rustup update stable
This will upgrade your current stable toolchain to version 1.95.0. If you haven't installed Rust yet, head to the official website to get rustup. For those eager to test upcoming features, you can switch to the beta or nightly channels using rustup default beta or rustup default nightly. Please report any bugs you encounter on the Rust issue tracker.
What is the cfg_select! macro and how does it work?
Rust 1.95.0 introduces cfg_select!, a macro that acts as a compile-time conditional selector, similar to a match on configuration predicates. It expands to the right-hand side of the first arm whose predicate evaluates to true. For example:
cfg_select! {
unix => {
fn foo() { /* unix specific functionality */ }
}
target_pointer_width = "32" => {
fn foo() { /* non-unix, 32-bit functionality */ }
}
_ => {
fn foo() { /* fallback implementation */ }
}
}
This macro serves a similar purpose to the popular cfg-if crate but with a different syntax. It can also be used for inline expressions, like:
let is_windows_str = cfg_select! {
windows => "windows",
_ => "not windows",
};
This makes conditional compilation more concise and readable directly within the language.
How do if-let guards work in match expressions?
Building on let chains stabilized in Rust 1.88, version 1.95.0 brings if let guards into match arms. This allows you to add a pattern-matching condition to a match arm. For instance:
match value {
Some(x) if let Ok(y) = compute(x) => {
// Both `x` and `y` are available here
println!("{}, {}", x, y);
}
_ => {}
}
Here, the arm matches only if value is Some(x) and compute(x) returns Ok(y). The variables x and y are both in scope inside the arm's block. Note that the compiler does not consider the patterns inside if let guards for exhaustiveness checking, similar to traditional if guards.
What APIs were stabilized in Rust 1.95.0?
This release stabilizes a number of APIs across the standard library. Notable additions include:
- MaybeUninit conversions:
MaybeUninit<[T; N]>now implementsFrom<[MaybeUninit<T>; N]>and relatedAsRef/AsMuttraits. - Cell and bool:
Cell<[T; N]>gainsAsRefimplementations, andboolnow implementsTryFrom<{integer}>. - Atomic operations: Various atomic types (
AtomicPtr,AtomicBool,AtomicI*,AtomicU*) have newupdateandtry_updatemethods. - New modules and items: The
core::rangemodule now includesRangeInclusiveand its iterator. Also,core::hint::cold_pathis stabilized, and raw pointer methodsas_ref_uncheckedandas_mut_uncheckedare now available. - Collection mutations:
Vec,VecDeque, andLinkedListhave new methods likepush_mut,insert_mut, andpush_front_mutthat return mutable references.
For a complete list, see the detailed release notes.
How can I test future releases of Rust?
If you'd like to help the Rust team by testing upcoming features before they hit stable, you can use the beta or nightly channels. To switch, run:
rustup default beta
# or
rustup default nightly
You can also install a specific channel alongside your current setup without changing defaults. Use rustup toolchain install beta and then cargo +beta build for one-off builds. Remember to report any bugs you find to the Rust issue tracker – your feedback helps make the language better for everyone.
How does cfg_select! compare to the cfg-if crate?
The cfg_select! macro fulfills the same purpose as the popular cfg-if crate: compile-time conditional code selection based on configuration predicates. However, the syntax differs. In cfg_select!, arms are separated by => with a wildcard _ for the fallback, while cfg-if uses a more block-oriented style with if cfg!(...) checks. cfg_select! is built directly into the language, removing the need for an external dependency. It also supports more concise inline expressions, as shown above. Both tools are robust, but the native macro reduces boilerplate and streamlines conditional compilation in Rust projects.