Technology

Rust 1.95.0 Released: Introducing cfg_select! and Improved Pattern Matching

2026-05-06 22:03:09

What's New in Rust 1.95.0

The Rust team has announced the release of version 1.95.0, bringing significant enhancements to the language's conditional compilation and pattern matching capabilities. This update focuses on reducing boilerplate while maintaining Rust's core safety guarantees. Developers will find the new cfg_select! macro and improved match expressions particularly valuable for writing cleaner, more maintainable code.

Rust 1.95.0 Released: Introducing cfg_select! and Improved Pattern Matching
Source: blog.rust-lang.org

Updating to Rust 1.95.0

If you already have Rust installed via rustup, obtaining the latest stable release is straightforward:

$ rustup update stable

New users can install rustup from the official Rust website. For those interested in testing upcoming features, you can switch to the beta or nightly channels:

$ rustup default beta
$ rustup default nightly

We encourage all users to report any bugs they encounter on the GitHub issue tracker.

The cfg_select! Macro

Conditional compilation has long been a necessity in Rust, especially for cross-platform development. The cfg-if crate has been a popular solution, but Rust 1.95.0 now offers an official alternative: cfg_select!. This macro works like a compile-time match on configuration predicates, expanding to the right-hand side of the first matching arm.

Basic Usage

The macro accepts any number of arms, each consisting of a configuration predicate and a corresponding expression or block:

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

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

The underscore (_) serves as a catch-all, similar to the default arm in a match expression. This feature streamlines conditional code without relying on external crates.

if-let Guards in Match Expressions

Building on the let chains stabilized in Rust 1.88, version 1.95.0 extends this capability to match expressions. You can now use if let guards to combine pattern matching with conditional logic inside a single match arm:

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

This syntax keeps your code concise and expressive, eliminating the need for nested if let statements. Note that the compiler currently does not consider patterns in if let guards when checking exhaustiveness, so you may need to add a wildcard arm.

Stabilized APIs

Rust 1.95.0 stabilizes a number of APIs that improve ergonomics and safety. Here is a categorized overview:

Conversions and References for MaybeUninit and Cell

Integer to Boolean Conversion

Atomic Operations

Core Range and Hint

Raw Pointer Safety

Collection Mutators

For a complete list, refer to the detailed release notes.

Conclusion

Rust 1.95.0 continues the language's tradition of empowering developers with safe, efficient tools. The cfg_select! macro reduces reliance on third-party crates, while if-let guards in match expressions make pattern matching more flexible. Combined with the newly stabilized APIs, this release is a solid step forward for the ecosystem. Update today and give these features a try!

Explore

mmlive mmlive Active Exploitation of Critical Ivanti Flaw, Major Data Breaches, and Novel AI Threats Highlight This Week's Cybersecurity Landscape net88 vi68 Google’s $1.5 Million Bug Bounty: 10 Critical Changes to Android & Chrome Rewards 2king88 Closing the Digital Divide: A Practical Guide to Narrowing the Gender Gap in Generative AI Skills vi68 sv288 AI Agents Disrupt Entire Software Development Lifecycle, Experts Warn net88 sv288 2king88 Meta Unveils KernelEvolve: AI Agent Automates Chip Optimization, Boosts Model Performance by 60%