The Rust team recently released a new version of Rust 1.66.0. The main updates in the 1.66.0 stable version are as follows:

Explicit Discrimination for Enumerations with Fields

Enums with integer representations can now use explicit discrimination even if they have fields.

enum Foo {
    C(bool) = 42,

Previously, you could use explicit discrimination on represented enums, but only if none of their variants had fields. Explicit discrimination is useful when passing values ​​across language boundaries, since the representation of the enum needs to match in both languages.


When benchmarking or inspecting the machine code produced by a compiler, it is often useful to prevent optimizations from happening in certain places.In the example below, the function push_cap executed in a loop Vec::push 4 times.

fn push_cap(v: &mut Vec<i32>) {
    for i in 0..4 {

pub fn bench_push() -> Duration {
    let mut v = Vec::with_capacity(4);
    let now = Instant::now();
    push_cap(&mut v);

If you check the optimization output of the compiler on x86_64, you’ll see that it looks rather short.

  sub rsp, 24
  call qword ptr [rip + std::time::Instant::now@GOTPCREL]
  lea rdi, [rsp + 8]
  mov qword ptr [rsp + 8], rax
  mov dword ptr [rsp + 16], edx
  call qword ptr [rip + std::time::Instant::elapsed@GOTPCREL]
  add rsp, 24

In fact, we want to benchmark the entire function push_cap It has been optimized away!

We can use the new stable black_box function to solve this problem. Functionally, black_box It takes the value you pass it and passes it back directly.However, internally, the compiler will black_box Think of it as a function that can do anything to its input and return any value.

This is useful for disabling optimizations like the one we saw above.

use std::hint::black_box;

fn push_cap(v: &mut Vec<i32>) {
    for i in 0..4 {

cargo remove

In Rust 1.62.0 we introduced cargo add, a command-line tool for adding dependencies to your you can use cargo remove to remove dependencies.

stable API

  • [proc_macro::Span::source_text](<>)
  • [u*::{checked_add_signed, overflowing_add_signed, saturating_add_signed, wrapping_add_signed}](<>)
  • [i*::{checked_add_unsigned, overflowing_add_unsigned, saturating_add_unsigned, wrapping_add_unsigned}](<>)
  • [i*::{checked_sub_unsigned, overflowing_sub_unsigned, saturating_sub_unsigned, wrapping_sub_unsigned}](<>)
  • [BTreeSet::{first, last, pop_first, pop_last}](<>)
  • [BTreeMap::{first_key_value, last_key_value, first_entry, last_entry, pop_first, pop_last}](<>)
  • [impl TryFrom<Vec<T>> for Box<[T; N]>](<>)
  • [core::hint::black_box](<>)
  • [Duration::try_from_secs_{f32,f64}](<>)
  • [Option::unzip](<>)
  • [std::os::fd](<>)

other changes

There are other changes in Rust 1.66, including

  • You can now use in the pattern ..=X scope.
  • The Linux version now optimizes the rustc frontend and LLVM backend with LTO and BOLT respectively, improving runtime performance and memory usage.

More details can be found at:

#Rust #released #News Fast Delivery

Leave a Comment

Your email address will not be published. Required fields are marked *