Rust 1.95.0 Lands: New `cfg_select!` Macro and Match Guards Boost Compile-Time Flexibility

Rust 1.95.0 Released: Streamlined Conditional Compilation and Enhanced Pattern Matching Take Center Stage

The Rust team has officially released version 1.95.0, bringing two long-anticipated features to stable: the cfg_select! macro and if-let guards in match expressions. The update is available immediately via rustup update stable.

Rust 1.95.0 Lands: New `cfg_select!` Macro and Match Guards Boost Compile-Time Flexibility
Source: blog.rust-lang.org

“This release empowers developers with more ergonomic compile-time conditionals and richer pattern matching,” said a Rust Core Team representative. “It’s another step toward making Rust safer and more expressive without sacrificing performance.”

cfg_select! Macro: A First-Class Compile-Time Switch

Rust 1.95.0 introduces the cfg_select! macro, which acts as a compile-time match on configuration predicates. It fulfills the same role as the popular cfg-if crate but with a distinct syntax.

“The macro expands to the right-hand side of the first arm whose configuration predicate evaluates to true,” the team explained. This eliminates the need for nested cfg! attributes in many cases.

Example usage:

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

For simple value selection:

let is_windows_str = cfg_select! {
    windows => "windows",
    _ => "not windows",
};

If-Let Guards in Match: Unlocking Nested Pattern Logic

Building on the let chains stabilized in Rust 1.88, version 1.95.0 extends that power to match arms. Developers can now use if let guards to conditionally match based on further pattern matching.

“Both the outer pattern variable and the inner guard variable are available inside the arm,” noted the Rust team. Example:

match value {
    Some(x) if let Ok(y) = compute(x) => {
        println!("{}, {}", x, y);
    }
    _ => {}
}

Note: The compiler currently does not consider patterns in if let guards as part of exhaustiveness evaluation — similar to regular if guards.

Stabilized APIs: Safer Uninitialized Memory and Atomic Operations

The release also stabilizes over two dozen APIs, focusing on MaybeUninit, Cell, Atomic*, and collection mutability improvements.

Key Stabilizations

  • MaybeUninit<[T; N]>: New From, AsRef, and AsMut implementations for easier conversion between array types.
  • AtomicPtr, AtomicBool, AtomicIn, AtomicUn: update and try_update methods for atomic read-modify-write patterns without locks.
  • bool: TryFrom<{integer}>: Safe fallible conversion from any integer to bool.
  • Raw pointer methods: as_ref_unchecked and as_mut_unchecked for unchecked references from raw pointers.
  • Collection push/insert mut: Vec::push_mut, Vec::insert_mut, and similar for VecDeque and LinkedList.
  • New modules: core::range with RangeInclusive and its iterator, plus core::hint::cold_path for marking unlikely branches.

The full list of stabilized APIs is available in the official release notes.

Background: Rust’s Rapid Release Cycle

Rust follows a predictable six-week release cadence. Version 1.95.0 continues this tradition, building on the let chains feature from 1.88 and responding to community demand for a built-in cfg! matching macro.

The cfg-if crate, which cfg_select! now standardizes, has been a staple in the ecosystem for handling conditional compilation in a readable way. Its inclusion as a language macro reduces external dependencies and improves compiler integration.

What This Means for Rust Developers

“With cfg_select!, platform-specific code becomes more readable and less error-prone,” said one Rust community reviewer. “It’s a natural replacement for chains of cfg! attributes.”

The if-let guard feature lets developers write concise match arms that would previously require nested matches or separate functions. This is particularly valuable in parsers, network protocol handlers, and any code with layered validation.

Stabilized APIs like Atomic*::update provide safer atomic operations without manual loops, while MaybeUninit improvements simplify low-level memory management. Performance-sensitive projects, such as game engines and embedded systems, will benefit directly.

“Upgrade today via rustup update stable,” the team urged. They also encourage testing future releases on beta and nightly channels to catch regressions early.

For complete details, see the official announcement.

Tags:

Recommended

Discover More

How to Spot and Prevent Fabricated Citations in Academic Research5 Critical Updates on arXiv's New Policy Against AI-Generated SubmissionsPython Developers Gain New GUI Skills: Build a Calculator with TkinterPhoto Platform SmugMug Warns: Axing Section 230 Could ‘Bankrupt’ Small Businesses and Delay Wedding PhotosReal-Time Hallucination Correction: A Self-Healing Layer for RAG Systems