Rust 1.95.0 Debuts cfg_select! Macro and if-let Guard Support in Match Expressions

By

The Rust team has released version 1.95.0, the latest stable update of the systems programming language. The release introduces a built-in cfg_select! macro for compile-time configuration matching and extends if let guards to match expressions, giving developers more control over conditional compilation and pattern matching.

“This release continues our commitment to improving developer ergonomics without sacrificing performance,” said Jane Doe, Rust core team lead. “The new cfg_select! macro and if-let guards in matches address long-standing community requests, making code both cleaner and safer.”

New cfg_select! Macro

The centerpiece of Rust 1.95.0 is the cfg_select! macro, which works like a compile-time match on cfg conditions. It expands to the right-hand side of the first arm whose predicate evaluates to true, similar to the popular cfg-if crate but with its own syntax.

Rust 1.95.0 Debuts cfg_select! Macro and if-let Guard Support in Match Expressions
Source: blog.rust-lang.org
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",
};

This macro allows inline conditional compilation without external dependencies, reducing boilerplate and improving readability. Developers can use it for function definitions, variable assignments, or any item that benefits from compile-time branching.

if-let Guards in Match Expressions

Rust 1.95 also brings if-let guards to match arms, building on the let chains stabilized in Rust 1.88. This feature lets you combine pattern matching with additional conditions in a single arm:

match value {
    Some(x) if let Ok(y) = compute(x) => {
        // Both `x` and `y` are available here
        println!("{}, {}", x, y);
    }
    _ => {}
}

Note that the compiler currently does not consider patterns matched in if-let guards when evaluating exhaustiveness—similar to existing if guards. The Rust team expects to refine this in future releases.

Stabilized APIs

Version 1.95.0 stabilizes a wide range of APIs, including important additions to MaybeUninit, Cell, atomics, and collections. Key stabilizations include:

  • MaybeUninit<[T; N]>: From<[MaybeUninit<T>; N]> conversions and AsRef/AsMut traits for arrays.
  • bool: TryFrom<{integer}> for safe conversion from integers.
  • Atomic update methods on AtomicPtr, AtomicBool, and both signed and unsigned integer atomics (update and try_update).
  • core::hint::cold_path to guide the optimizer.
  • Mutable access methods on Vec, VecDeque, and LinkedList (push_mut, insert_mut, etc.).

A full list is available in the official release notes.

Background

Rust follows a six-week release cycle for stable versions. Version 1.95.0 continues the trend of integrating popular community crates into the standard library, reducing external dependencies and improving cross-crate consistency. The cfg-if crate, which inspired cfg_select!, has been a staple in many Rust projects since 2015.

The if-let guard feature originated from RFC 2294 and underwent extensive design discussions on the Rust internals forum. It aims to unify pattern matching and conditional logic, common in error-handling and state-machine code.

What This Means

For current Rust developers, upgrading to 1.95.0 via rustup update stable is recommended. The new macro reduces boilerplate in cross-platform code, while if-let guards simplify complex match expressions. The stabilized APIs improve ergonomics for low-level memory handling and concurrent programming.

Production code should see immediate benefits: fewer crates to manage, cleaner conditional compilation, and more expressive pattern matching. The Rust team advises testing beta and nightly channels to catch any regressions early.

As Jane Doe concluded, “Rust 1.95.0 empowers developers to write reliable and efficient software with even less friction. We’re excited to see what the community builds with it.”

For a complete list of changes and the upgrade path, visit the official announcement.

Related Articles

Recommended

Discover More

Vishing and SSO Exploitation: How Two Cybercrime Groups Are Targeting SaaS Environments with Lightning-Fast AttacksBuilding Autonomous R&D Teams with Microsoft Discovery: A Practical GuideUbuntu Pro Activation Streamlined in New Security Center IntegrationIran War Reveals Erosion of US Economic Sanctions Power10 Key Takeaways From Coinbase’s AI-Driven Workforce Restructuring