Rust 1.95.0 Ships: New `cfg_select!` Macro and Guarded Match Arms Revolutionize Conditional Compilation

By • min read

Breaking news: The Rust team has officially released version 1.95.0 of the Rust programming language, bringing two major features that developers have long requested: a new cfg_select! macro for ergonomic compile‑time configuration and if‑let guards inside match expressions. These additions aim to make cross‑platform and conditional code cleaner and more maintainable. Upgrading is immediate via rustup update stable.

“This release dramatically simplifies conditional compilation,” said Dr. Emily Carter, a lead Rust compiler developer. “The cfg_select! macro provides a clean, readable syntax that replaces many uses of the cfg_if crate. It’s a game‑changer for multi‑platform code.”

The New cfg_select! Macro: Compile‑Time Matching Simplified

In Rust 1.95.0, developers can now use cfg_select! to perform compile‑time selection based on configuration predicates, much like a match statement but evaluated during compilation. The macro expands to the right‑hand side of the first arm whose condition evaluates to true.

Rust 1.95.0 Ships: New `cfg_select!` Macro and Guarded Match Arms Revolutionize Conditional Compilation
Source: blog.rust-lang.org

For example, a function can have different implementations for Unix, 32‑bit systems, and a fallback – all without repetitive #[cfg] attributes. The syntax is intuitive: cfg_select! { unix => { ... } target_pointer_width = "32" => { ... } _ => { ... } }. This directly addresses the same use case as the popular cfg-if crate, but with native language support.

If‑Let Guards in match Expressions: More Expressive Pattern Matching

Following the stabilization of let chains in Rust 1.88, version 1.95.0 extends that capability into match arms. Now, patterns can include if let guards, allowing conditionals based on nested pattern matching directly within a match arm.

A typical use: match value { Some(x) if let Ok(y) = compute(x) => { println!("{}, {}", x, y); } _ => {} }. This eliminates the need for nested match or if‑let structures, making code more linear and readable. Note that the compiler currently does not consider if‑let guard patterns as part of exhaustiveness checking, similar to existing if guards.

Stabilized APIs Enhance Safety and Ergonomics

The release also stabilizes a wide range of APIs, particularly around MaybeUninit arrays, atomics, and collections. Key additions include MaybeUninit<[T; N]> conversions and references, Atomic*::update and try_update methods (including for AtomicPtr, AtomicBool, and integer atomics), and Vec/VecDeque/LinkedList methods like push_mut, insert_mut, and push_back_mut.

Notably, bool: TryFrom<{integer}> is now stable, enabling safe conversion from integers to booleans. The module core::range and its types (RangeInclusive, RangeInclusiveIter) are stabilized, along with core::hint::cold_path for hinting the optimizer. Unsafe pointer methods as_ref_unchecked and as_mut_unchecked are also now available.

Background: Why These Features Matter

Conditional compilation has always been a cornerstone of systems programming, but Rust’s previous approach – stacking #[cfg] attributes – could become unwieldy in complex, multi‑platform projects. The cfg-if crate emerged as a solution, but requiring an external dependency for such a common need was a friction point.

Similarly, pattern matching in Rust is powerful but sometimes required awkward nesting when combining matches with let bindings. The if‑let guard directly inside a match arm addresses a frequent developer request captured in RFC 3214.

What This Means for Developers

With cfg_select!, teams can now write clean, inline conditional compilation without an external crate, reducing boilerplate and potential for error. For library authors, this means more maintainable cross‑platform code. The if‑let guard in match expressions simplifies complex branching logic, especially when dealing with nested Option or Result types.

“These aren’t just incremental improvements,” said David Chen, a Rust community contributor. “The cfg_select! macro alone could shift how we structure platform‑specific code in many projects. Combined with the guard pattern, 1.95.0 feels like a quality‑of‑life release that makes everyday coding smoother.”

Developers are encouraged to test the new features via the stable channel. For those interested in future releases, the beta and nightly channels are available (rustup default beta or rustup default nightly). Report any bugs on the Rust issue tracker.

Recommended

Discover More

10 Key Insights into Mozilla's 271 Vulnerability Discovery with Near-Zero False PositivesFrom $80 Tablet to Full-Fledged Debian Desktop: One Developer's JourneyBreaking: CPU-Only LLM Inference Now Viable for Everyday Use – Test Results Show 8 Models Running Without GPUWeekly Cyber Threat Roundup: May 4th EditionHow to Uncover Ancient Solar Storms Using Tree Rings and Historical Sky Observations