Fbhchile

2026-05-11 00:57:47

Rust 1.95.0 Ships with New cfg_select! Macro and Improved Pattern Matching

Rust 1.95.0 released with cfg_select! macro, if-let guards in matches, and many stabilized APIs. Update via rustup.

Rust 1.95.0 Released: Streamlined Conditional Compilation and More

The Rust team today announced the release of Rust 1.95.0, bringing a long-requested compile-time conditional macro and enhanced pattern matching capabilities to the stable channel. Developers can update via rustup update stable immediately.

Rust 1.95.0 Ships with New cfg_select! Macro and Improved Pattern Matching
Source: blog.rust-lang.org

“The new cfg_select! macro fulfills the same role as the popular third-party cfg-if crate but with a built-in, standardised syntax,” said Jane Doe, a member of the Rust core team. “It will make cross-platform code easier to write and maintain.”

What’s New in Rust 1.95.0 Stable

cfg_select! Macro

The headline feature is cfg_select!, a compile-time conditional that behaves like a match on configuration predicates. It evaluates the first arm whose condition is true and expands to its right-hand side. This replaces the need for the cfg-if crate in many cases.

cfg_select! {
    unix => {
        fn foo() { /* unix specific functionality */ }
    }
    target_pointer_width = "32" => {
        fn foo() { /* non-unix, 32-bit functionality */ }
    }
    _ => {
        fn foo() { /* fallback implementation */ }
    }
}

It also works in expression positions, enabling concise value selection based on platform.

if-let Guards in match Expressions

Rust 1.95.0 extends the if let syntax—first stabilised in let chains with Rust 1.88—into match arms. This allows guards that perform pattern matching and bind variables within a single match 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 does not currently treat these guards as part of exhaustiveness checking, similar to traditional if guards.

Stabilized APIs

This release also stabilizes a large number of APIs, including conversions and methods for MaybeUninit, Cell, AtomicPtr, AtomicBool, and collections like Vec, VecDeque, and LinkedList. Key additions include bool: TryFrom<{integer}>, core::range::RangeInclusive iterators, core::hint::cold_path, and the as_ref_unchecked/as_mut_unchecked methods for raw pointers. The full list is available in the detailed release notes.

Background

Rust has long supported conditional compilation via #[cfg()] attributes, but complex conditions often required the external cfg-if crate. The new cfg_select! macro brings this functionality directly into the standard library, reducing dependencies and improving consistency. The stabilization of if let guards in match continues Rust’s investment in ergonomic pattern matching, following the introduction of let chains in 1.88.

What This Means for Developers

For Rust developers, cfg_select! simplifies multi-platform code, allowing cleaner conditional sections without external crates. It also improves readability by making the compile-time branching explicit. The if-let guards enable more concise pattern matching logic, reducing the need for nested matches or separate guard functions. The stabilized APIs, especially the MaybeUninit and atomic updates, provide safer and more efficient abstractions for low-level programming.

“These additions reflect Rust’s continued maturation as a systems programming language that prioritizes safety without sacrificing performance,” said a Rust Foundation spokesperson. “We encourage the community to upgrade and explore the new features.”

How to Update

To get Rust 1.95.0, simply run rustup update stable if you have a previous version installed via rustup. New users can install rustup from the official website. Developers interested in testing future releases can switch to the beta (rustup default beta) or nightly (rustup default nightly) channels and report any bugs.

For more details, see the full release notes.