Rust 1.95.0 Introduces cfg_select! Macro, if-let Guards in Matches, and More

By

What's New in Rust 1.95.0

The Rust team has released version 1.95.0, bringing a handful of new features and stabilizations that make the language even more expressive and efficient. This release introduces a new cfg_select! macro, extends pattern matching capabilities with if-let guards, and stabilizes a wide range of APIs. If you already have Rust installed via rustup, simply run:

Rust 1.95.0 Introduces cfg_select! Macro, if-let Guards in Matches, and More
Source: blog.rust-lang.org
$ rustup update stable

If you haven’t installed Rust yet, head over to the official rustup page to get started. For those eager to test upcoming features, you can switch to the beta or nightly channels with rustup default beta or rustup default nightly—and please report any bugs you find!

cfg_select! Macro: Compile‑Time Configuration Made Simpler

One of the standout additions in Rust 1.95.0 is the cfg_select! macro, which acts as a compile‑time conditional expression. It works much like a match statement but evaluates configuration predicates (like those used with #[cfg()]) at compile time. This fulfills the same purpose as the popular cfg-if crate, but with its own syntax.

Here’s a quick example:

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",
};

The macro expands to the right‑hand side of the first arm whose condition evaluates to true. This makes conditional compilation cleaner and more readable, especially when you have multiple platform‑ or architecture‑specific blocks.

if-let Guards in match Expressions

Building on the let chains stabilised in Rust 1.88, version 1.95.0 now brings if-let guards directly into match expressions. This allows you to combine pattern matching with a conditional that itself performs pattern matching, all within a single arm.

For example:

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 consider patterns used in if-let guards when checking exhaustiveness—just as with regular if guards. This feature makes code more concise and powerful, especially when dealing with nested results or options.

Stabilized APIs

Rust 1.95.0 also stabilizes a large set of APIs, many of which improve ergonomics around MaybeUninit, Cell, atomics, and collection types. Below is a full list:

Conversions and References for MaybeUninit and Cell Arrays

Atomic Operations

New Modules and Core Additions

Pointer Methods

Collection Mutability Enhancements

Get Started with Rust 1.95.0

To upgrade, simply run rustup update stable. For full details, check the detailed release notes. As always, the Rust community welcomes your feedback and contributions—happy coding!

Tags:

Related Articles

Recommended

Discover More

Securing Your Autonomous AI Agent: A Practical Guide to Safely Deploying Tools Like OpenClawHow to Score the Best May MacBook Pro Deals: M5 Pro & M5 Max Models from $1,949How Scientists Uncover the Hidden Phases of Ice: A Step-by-Step Guide10 Reasons Why DJI, Once the King of Consumer Drones, Now Faces a Global Sales Crisis10 Essential Steps to Build a Serverless Spam Classifier with AWS and Scikit-Learn