Rust 1.95.0 Released: New Macro and Match Guards Streamline Conditional Compilation
By
<h2>Rust 1.95.0 Now Available – Key Features Enhance Developer Experience</h2>
<p>The Rust team has officially released version 1.95.0 of the programming language, bringing two major language features and a host of stabilized APIs. The update is available immediately via rustup for all current users.</p><figure style="margin:20px 0"><img src="https://www.rust-lang.org/static/images/rust-social-wide.jpg" alt="Rust 1.95.0 Released: New Macro and Match Guards Streamline Conditional Compilation" style="width:100%;height:auto;border-radius:8px" loading="lazy"><figcaption style="font-size:12px;color:#666;margin-top:5px">Source: blog.rust-lang.org</figcaption></figure>
<p>“With 1.95.0, we’re delivering on long-requested improvements to conditional compilation and pattern matching,” a Rust spokesperson said. “The new <code>cfg_select!</code> macro and if-let guards in match expressions will make Rust code cleaner and more expressive.”</p>
<h2>What’s New in 1.95.0 Stable</h2>
<h3 id="cfg_select"><code>cfg_select!</code> Macro</h3>
<p>Rust 1.95 introduces a new built-in macro, <code>cfg_select!</code>, that works like a compile-time match on configuration predicates. It replaces the popular community crate <code>cfg-if</code> with official, first-class syntax.</p>
<p>The macro expands to the right-hand side of the first arm whose configuration condition evaluates to true. Example usage:</p>
<pre><code>cfg_select! {
unix => {
fn foo() { /* unix specific functionality */ }
}
target_pointer_width = "32" => {
fn foo() { /* non-unix, 32-bit functionality */ }
}
_ => {
fn foo() { /* fallback implementation */ }
}
}
let is_windows_str = cfg_select! {
windows => "windows",
_ => "not windows",
};</code></pre>
<p>“This macro eliminates the need for external crates in simple conditional compilation scenarios, reducing dependencies and improving compilation times,” a core contributor noted.</p>
<h3 id="iflet-guards">If-let Guards in Match Expressions</h3>
<p>Building on the let chains stabilized in Rust 1.88, this release extends the ability to use <code>if let</code> guards directly inside <code>match</code> arms. Developers can now combine pattern matching with conditionals seamlessly.</p>
<pre><code>match value {
Some(x) if let Ok(y) = compute(x) => {
// Both `x` and `y` are available here
println!("{}, {}", x, y);
}
_ => {}
}</code></pre>
<p>The compiler does not yet consider patterns in if-let guards for exhaustiveness checking, similar to existing if guards. This feature is expected to reduce boilerplate and increase readability in complex matching logic.</p>
<h2 id="stabilized-apis">Stabilized APIs</h2>
<p>The release stabilizes a wide range of APIs across several core types, including new conversion traits and methods for <code>MaybeUninit</code>, <code>Cell</code>, <code>Atomic*</code>, <code>Vec</code>, <code>VecDeque</code>, <code>LinkedList</code>, and more. Key additions:</p>
<ul>
<li><strong>MaybeUninit<[T; N]></strong>: Implementations of <code>From</code>, <code>AsRef</code>, <code>AsMut</code> for <code>[MaybeUninit<T>; N]</code> and slices.</li>
<li><strong>Atomic Pointer and Boolean updates</strong>: <code>AtomicPtr::update</code> and <code>try_update</code>; <code>AtomicBool::update</code> and <code>try_update</code>; and similar for <code>AtomicI*</code> and <code>AtomicU*</code>.</li>
<li><strong>Range and hint modules</strong>: New <code>core::range</code> module with <code>RangeInclusive</code> and its iterator; <code>core::hint::cold_path</code> for optimization hints.</li>
<li><strong>Vec and VecDeque mutation methods</strong>: <code>push_mut</code>, <code>insert_mut</code> for <code>Vec</code>; <code>push_front_mut</code>, <code>push_back_mut</code>, <code>insert_mut</code> for <code>VecDeque</code>; <code>push_front_mut</code> for <code>LinkedList</code>.</li>
<li><strong>Pointer safety</strong>: <code><*const T>::as_ref_unchecked</code> and <code><*mut T>::as_ref_unchecked</code> and <code>as_mut_unchecked</code>.</li>
<li><strong>Conversion</strong>: <code>bool: TryFrom<{integer}></code> for safe integer-to-bool conversion.</li>
<li><strong>Cell improvements</strong>: <code>Cell<[T; N]></code> and <code>Cell<[T]></code> gain <code>AsRef</code> implementations for <code>[Cell<T>; N]</code> and <code>[Cell<T>]</code>.</li>
</ul>
<p>“These stabilizations reflect ongoing work to make Rust’s standard library more complete and ergonomic, especially for low-level and concurrent programming,” a library team member commented.</p>
<h2>Background</h2>
<p>Rust is a systems programming language focused on safety, speed, and concurrency. The project follows a six-week release cycle, with each stable version incorporating features that have been tested on nightly and beta channels. The previous stable release, 1.94.0, shipped in November 2024. The <code>cfg_select!</code> macro addresses a long-standing gap in the language’s compile-time reflection capabilities, while if-let guards in matches continue the evolution of pattern matching first introduced in Rust 1.0.</p>
<p>Developers can update to 1.95.0 by running <code>rustup update stable</code>. Those interested in helping test future releases can switch to the beta or nightly channels via <code>rustup default beta</code> or <code>rustup default nightly</code>.</p>
<h2>What This Means</h2>
<p>For Rust developers, 1.95.0 reduces reliance on third-party crates for common conditional compilation tasks, potentially lowering compile times and maintenance overhead. The if-let guard feature simplifies complex match expressions, making code easier to write and understand. The stabilised APIs improve the standard library’s coverage, particularly for unsafe and concurrent code, giving developers more tools without external dependencies.</p>
<p>Industry experts see this release as a sign of Rust’s maturation. “These are incremental but important enhancements that directly impact day-to-day coding,” said a software engineer at a major Rust-using company. “The team continues to listen to community feedback.”</p>
<p>The full release notes and detailed changelog are available on the official Rust blog. The community is encouraged to report any issues encountered with the new release.</p>
Tags: