What Is New in Rust 1.95
| Category | Highlights |
|---|---|
| New Features | cfg_select! macro for compile-time selection; if-let guards inside match arms |
| Improvements | Many standard library APIs stabilized, especially for const fn contexts (MaybeUninit, atomic updates, Vec push_mut, Layout, etc.) |
| Breaking Changes | Custom JSON target specifications are no longer supported on the stable channel |
How does the new cfg_select! macro simplify conditional compilation?
The cfg_select! macro lets you write a compile-time match on cfg predicates, eliminating the need for external crates like cfg-if. In practice you place a list of predicates followed by the code to emit for the first true branch.
cfg_select! {
unix => {
fn foo() { /* unix specific */ }
}
target_pointer_width = "32" => {
fn foo() { /* 32-bit fallback */ }
}
_ => {
fn foo() { /* generic fallback */ }
}
}
This matters if you maintain a codebase that targets many platforms; the macro keeps the conditional logic in one place and expands to exactly one implementation.
Can I use if let guards inside match arms in Rust 1.95?
Yes, Rust 1.95 extends let-chains to match guards, allowing an if let expression to appear after the if keyword in a pattern guard.
match value {
Some(x) if let Ok(y) = compute(x) => {
println!("{}, {}", x, y);
}
_ => {}
}
Watch out for the fact that these guards are not considered in exhaustiveness checking, so the compiler will not warn you if a guard makes a branch unreachable.
What standard library APIs became const-stable or stabilized in Rust 1.95?
Rust 1.95 brings a large number of new stable APIs and makes many existing ones usable in const contexts, enabling richer compile-time computation.
- Const context improvements: Many APIs (such as
fmt::from_fn,ControlFlow::is_break,ControlFlow::is_continue, and others) are now stable inconst fn. - Notable stabilizations:
Vec::push_mut,Vec::insert_mut- Multiple
MaybeUninitandCellconversions for arrays - Atomic update methods:
Atomic*::update/try_update Layout::repeat,Layout::dangling_ptr, etc.core::rangemodule andcore::hint::cold_path
In production this means you can build richer const-evaluated data structures and low-level code without nightly features.
What breaking change does Rust 1.95 introduce regarding custom JSON target specifications?
Rust 1.95 removes support for passing a custom JSON target specification to rustc on the stable channel.
Most teams will not be affected because building the standard library already required nightly features, but if you relied on a bespoke JSON target for cross-compilation you will need to switch to the nightly toolchain or adopt the emerging custom-target workflow.
FAQ
Is cfg_select! a drop-in replacement for the cfg-if crate?
It provides similar functionality with a different syntax. For example cfg_select! { windows => "win", _ => "other" } can replace a cfg_if! block.
Do if let guards affect match exhaustiveness checking?
No, the compiler still treats the guard as a runtime condition and does not count it toward exhaustiveness.
Which APIs are now const-stable or newly stabilized?
Many APIs, notably Vec::push_mut/insert_mut, MaybeUninit array conversions, atomic update methods, and Layout utilities. A number of previously stable functions are also now available in const contexts.
Will my builds break because of the removal of JSON target specs?
Only if you were using custom JSON targets on the stable channel; otherwise builds remain unchanged.
How do I upgrade to Rust 1.95 using rustup?
Run rustup update stable to fetch the latest stable release.
Can I still use custom target specifications on stable?
No, custom JSON target specifications are no longer supported on the stable channel as of 1.95.