Damfinos
ArticlesCategories
Technology

Rust 1.95.0: What's New in the Latest Stable Release

Published 2026-05-13 11:49:07 · Technology

Rust 1.95.0 Now Available

The Rust team has released version 1.95.0 of the Rust programming language, bringing new features and improvements to enhance developer productivity and code reliability. This update introduces a compile-time conditional macro, extends pattern matching capabilities, and stabilizes a wide range of APIs. Users can upgrade via rustup update stable if they already have Rust installed. For those new to Rust, visit the official installation page to get started. Developers interested in testing upcoming releases can switch to the beta channel (rustup default beta) or nightly channel (rustup default nightly) and report any bugs encountered.

Rust 1.95.0: What's New in the Latest Stable Release
Source: blog.rust-lang.org

New Compile-Time Conditional Macro: cfg_select!

Rust 1.95.0 introduces the cfg_select! macro, which provides a convenient way to choose code branches at compile time based on configuration predicates. This macro functions similarly to a match expression on cfg attributes, fulfilling the same purpose as the popular cfg-if crate but with a different syntax. The macro expands to the right-hand side of the first arm whose condition evaluates to true. Here are some examples:

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

This macro simplifies conditional compilation by allowing multiple conditions to be evaluated in a single expression, improving code readability and maintainability.

Enhanced Pattern Matching with if let Guards

Building on the let chains stabilized in Rust 1.88, version 1.95.0 brings similar functionality to match expressions. Developers can now use if let guards within match arms to run additional pattern matching conditionally. This enables more expressive control flow:

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 patterns matched in if let guards as part of exhaustiveness checking, similar to regular if guards. This feature expands the versatility of pattern matching without sacrificing clarity.

Stabilized APIs and Improvements

Rust 1.95.0 stabilizes a significant number of APIs across standard library types, including conversions and references for MaybeUninit, Cell, and atomic types. Key additions include:

  • MaybeUninit arrays: New From, AsRef, and AsMut implementations for MaybeUninit<[T; N]> and [MaybeUninit<T>; N].
  • Cell arrays and slices: AsRef implementations for Cell<[T; N]> and Cell<[T]>.
  • Boolean conversion: bool: TryFrom<{integer}> allows safe conversion from integers.
  • Atomic operations: New update and try_update methods for AtomicPtr, AtomicBool, and AtomicIn/AtomicUn (likely referring to AtomicI/AtomicU types, as per original). These facilitate atomic read-modify-write patterns.
  • Range module: The new core::range module provides RangeInclusive and its iterator.
  • Hint for cold paths: core::hint::cold_path helps optimize branch prediction.
  • Pointer methods: as_ref_unchecked and as_mut_unchecked for raw pointers eliminate some safety boilerplate.
  • Collection mutations: Vec::push_mut, Vec::insert_mut, and similar methods for VecDeque and LinkedList allow direct mutation of elements returned by index.

These additions enhance ergonomics and safety across common programming patterns.

How to Get Started with Rust 1.95.0

To upgrade your existing installation, run rustup update stable. If you are new to Rust, install rustup from the official website and follow the instructions. For a complete list of changes, consult the detailed release notes. As always, report any issues on the Rust issue tracker to help improve the language.