Latest in branch 1.66
1.66.1
Released 10 Jan 2023
(3 years ago)
SoftwareRust
Version1.66
Initial release1.66.0
15 Dec 2022
(3 years ago)
Latest release1.66.1
10 Jan 2023
(3 years ago)
Support status27 Jan 2023
(Ended 3 years, 4 months ago)
Release noteshttps://github.com/rust-lang/rust/releases/tag/1.66.1
Source codehttps://github.com/rust-lang/rust/tree/1.66.1
Downloadhttps://github.com/rust-lang/rust/releases/tag/1.66.1
Rust 1.66 ReleasesView full list

What Is New in Rust 1.66

CategoryHighlights
New FeaturesExplicit discriminants on enums with fields, std::hint::black_box, cargo remove subcommand
Improvements..=X range patterns, Linux builds use LTO and BOLT for faster binaries

How can I assign explicit discriminants to enum variants that have fields?

Rust 1.66 lets you give a numeric discriminant to any enum variant, even when the variant carries data.

#[repr(u8)]
enum Foo {
    A(u8),
    B(i8),
    C(bool) = 42,
}

In practice this is useful for FFI where the exact layout must match a C enum. Variants without an explicit value keep the automatically incremented discriminants, so you can mix explicit and implicit values without inserting dummy variants.

How do I prevent the compiler from optimizing away code in benchmarks?

The newly stabilized std::hint::black_box acts as an opaque barrier that tells the optimizer it cannot assume anything about the value.

use std::hint::black_box;

fn push_cap(v: &mut Vec<i32>) {
    for i in 0..4 {
        v.push(i);
        black_box(v.as_ptr());
    }
}

This matters if you need to measure the cost of a loop or a function call; without black_box the compiler may elide the entire body.

How can I remove a dependency from Cargo.toml via the command line?

Rust 1.66 adds the cargo remove subcommand, mirroring the earlier cargo add workflow.

cargo remove serde

It edits Cargo.toml in place, removes the entry from the [dependencies] table, and updates the lock file, saving a manual edit.

What new pattern matching capabilities does Rust 1.66 introduce?

You can now use inclusive range patterns with the ..=X syntax directly in match arms.

match value {
    0..=10 => println!("small"),
    11..=100 => println!("medium"),
    _ => println!("large"),
}

This improves readability and eliminates the need for separate guard clauses for simple numeric ranges.

How does Rust 1.66 improve Linux build performance?

Linux builds now enable Link-Time Optimization (LTO) for the rustc frontend and BOLT for the LLVM backend.

In practice this reduces both runtime execution time and the memory footprint of the generated binaries, especially for large crates with many generic instantiations.

Frequently Asked Questions

Can I use explicit discriminants on enums that also have data fields?
Yes, Rust 1.66 allows you to write a discriminant after the variant name even when the variant carries payloads.

Do I need to import anything to use black_box?
You only need to add use std::hint::black_box; at the top of your file.

Is cargo remove safe to use on a workspace with multiple crates?
It removes the dependency from the current crate's Cargo.toml and updates the lock file, leaving other crates untouched.

What syntax do I write for an inclusive range in a match arm?
You write 0..=10 to match any value from 0 through 10 inclusive.

Will enabling LTO in Linux builds increase compile time?
Yes, compile time may be slightly higher, but the resulting binaries run faster and use less memory.

How do I see the discriminant value of a field-less enum variant?
You can cast it like Variant as u8, but for enums with fields you need unsafe code or std::mem::discriminant.

Releases In Branch 1.66

VersionRelease date
1.66.110 Jan 2023
(3 years ago)
1.66.015 Dec 2022
(3 years ago)