Latest in branch 1.80
1.80.1
Released 08 Aug 2024
(1 year ago)
SoftwareRust
Version1.80
Initial release1.80.0
25 Jul 2024
(1 year ago)
Latest release1.80.1
08 Aug 2024
(1 year ago)
Support status05 Sep 2024
(Ended 1 year, 9 months ago)
Release noteshttps://github.com/rust-lang/rust/releases/tag/1.80.1
Source codehttps://github.com/rust-lang/rust/tree/1.80.1
Downloadhttps://github.com/rust-lang/rust/releases/tag/1.80.1
Rust 1.80 ReleasesView full list

What Is New in Rust 1.80

CategoryHighlights
New FeaturesLazyLock, LazyCell, exclusive range patterns, Cargo cfg checking
ImprovementsConst-stabilized APIs, enhanced exhaustiveness checking, new lints for range patterns

How do LazyLock and LazyCell simplify static initialization?

LazyLock and LazyCell let you embed the initializer directly in the cell, removing the need for separate get_or_init calls.

Both types are drop-in replacements for the classic OnceLock/OnceCell pattern, but they store the closure that creates the value. LazyLock is thread-safe and can be used in static items, while LazyCell is single-threaded and works well with thread_local! storage.

use std::sync::LazyLock;
use std::time::Instant;

static LAZY_TIME: LazyLock<Instant> = LazyLock::new(Instant::now);

fn main() {
    let start = Instant::now();
    std::thread::scope(|s| {
        s.spawn(|| {
            println!("Thread lazy time: {:?}", LAZY_TIME.duration_since(start));
        });
        println!("Main lazy time: {:?}", LAZY_TIME.duration_since(start));
    });
}

In practice this reduces boilerplate and guarantees that the initialization runs exactly once, whichever thread accesses the static first.

What is the new exclusive range syntax in pattern matching?

Rust now allows exclusive endpoints in pattern ranges using a..b or ..b, mirroring the expression syntax of Range and RangeTo.

This lets you reuse the same constant for the end of one arm and the start of the next without subtracting one.

pub fn size_prefix(n: u32) -> &'static str {
    const K: u32 = 10u32.pow(3);
    const M: u32 = 10u32.pow(6);
    const G: u32 = 10u32.pow(9);
    match n {
        ..K => "",
        K..M => "k",
        M..G => "M",
        G.. => "G",
    }
}

Exhaustiveness checking has been tightened, and new lints (non_contiguous_range_endpoints, overlapping_range_endpoints) help you avoid accidental off-by-one errors.

How does Cargo's cfg checking help catch configuration mistakes?

Cargo 1.80 now enables --check-cfg for all known configuration names and values, emitting the unexpected_cfgs warning when a typo or unknown feature is used.

The warning points out the misspelled cfg, suggests the correct value, and even offers a quick fix by adding the missing feature to Cargo.toml. You can extend the known list via the [lints] table in the manifest.

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo, values("bar"))'] }

This early feedback prevents subtle build failures and keeps CI pipelines clean.

Which APIs are now usable in const contexts?

Several standard-library functions have been stabilized for use inside const blocks, expanding the compile-time capabilities of Rust.

Typical examples include methods on primitive wrappers and collection types that previously required runtime evaluation. This change enables more expressive const generics and compile-time calculations without resorting to nightly features.

In practice you can now write const fn that calls these newly const-stable APIs, simplifying embedded and no-std codebases.

Frequently Asked Questions

Do I need to modify existing OnceLock code to adopt LazyLock?
No, existing OnceLock code continues to work, but you can replace it with LazyLock for a more concise initializer.

Can LazyCell be placed in a static variable?
No, LazyCell does not implement Sync, so it cannot be used in a static, but it works in thread_local! storage.

What command enables the new cfg checks?
Cargo automatically enables them in Rust 1.80, you just need to compile with the stable toolchain.

How do I write an exclusive range pattern for values less than 1_000?
You write ..1_000 in the match arm.

Which APIs became const-stable in 1.80?
Several standard library functions such as Option::unwrap_or_default are now usable in const contexts.

Will the new range lints emit warnings by default?
Yes, non_contiguous_range_endpoints and overlapping_range_endpoints are enabled at the warn level.

Releases In Branch 1.80

VersionRelease date
1.80.108 Aug 2024
(1 year ago)
1.80.025 Jul 2024
(1 year ago)