Xtcworld

Rust 1.95.0 Released: New Macro, Match Guards, and More

Rust 1.95.0 releases with cfg_select! macro, if-let guards in match, and many stabilized APIs for arrays, atomics, collections, and more.

Xtcworld · 2026-05-08 00:01:23 · Technology

Overview of Rust 1.95.0

The Rust team is pleased to announce the release of version 1.95.0 of the Rust programming language. This update continues Rust's mission to empower developers to build reliable and efficient software. If you already have Rust installed via rustup, you can upgrade by running:

Rust 1.95.0 Released: New Macro, Match Guards, and More
Source: blog.rust-lang.org
$ rustup update stable

If you're new to Rust, visit the official website to install rustup and get started. For those interested in testing upcoming features, consider switching to the beta or nightly channels using rustup default beta or rustup default nightly. Please report any bugs you encounter to help improve future releases.

Key New Features in Rust 1.95.0

The cfg_select! Macro

One of the headline additions in this release is the cfg_select! macro, which provides a compile-time selection mechanism similar to a match statement but for configuration predicates. It works much like the popular cfg-if crate, though with a different syntax. The macro expands to the right-hand side of the first arm whose condition evaluates to true.

Here's an example showing platform-specific function implementations:

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

You can also use it in expressions:

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

If-Let Guards in Match Expressions

Building on the let chains stabilized in Rust 1.88, version 1.95.0 introduces if-let guards within match arms. This allows you to add a conditional pattern match directly inside a match arm, making code more concise and expressive.

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 the patterns in if-let guards as part of the exhaustiveness check of the overall match, similar to regular if guards. This feature enhances flexibility without breaking existing code.

Stabilized APIs in Rust 1.95.0

This release brings a wide range of API stabilizations that improve ergonomics and safety. Below are the highlights grouped by category.

MaybeUninit Array Conversions

Several From, AsRef, and AsMut implementations have been stabilized for MaybeUninit<[T; N]> and [MaybeUninit<T>; N], making it easier to work with uninitialized arrays safely.

Cell Array Access

New AsRef implementations for Cell<[T; N]> and Cell<[T]> allow borrowing the inner array or slice immutably, simplifying code that uses interior mutability.

Bool Conversion from Integer

A TryFrom<{integer}> implementation for bool is now stable, enabling fallible conversion from integers with clear semantics.

Atomic Operations

New update and try_update methods have been added for AtomicPtr, AtomicBool, and the generic atomic integer types. These provide a concise way to atomically modify values.

New Modules and Functions

  • core::range: A new module with RangeInclusive and RangeInclusiveIter types, offering more ergonomic range handling.
  • core::hint::cold_path: A new hint function to mark rarely executed code paths, aiding compiler optimization.
  • Pointer unchecked methods: <*const T>::as_ref_unchecked, <*mut T>::as_ref_unchecked, and <*mut T>::as_mut_unchecked allow unchecked conversion from raw pointers to references.

Collection Extensions

Several collections have gained new methods for inserting or pushing mutable references:

  • Vec::push_mut and Vec::insert_mut
  • VecDeque::push_front_mut, VecDeque::push_back_mut, and VecDeque::insert_mut
  • LinkedList::push_front_mut

Conclusion

Rust 1.95.0 brings meaningful improvements that enhance both compile-time flexibility and runtime safety. The cfg_select! macro simplifies conditional compilation, while if-let guards make pattern matching more powerful. With dozens of stabilized APIs, this release continues Rust's commitment to providing a robust, ergonomic language for systems programming. Upgrade today and explore the new possibilities!

Recommended