Announcing Rust 1.46.0

Announcing Rust 1.46.0

The Rust team is happy to announce a new version of Rust, 1.46.0. Rust is a programming language that is empowering everyone to build reliable and efficient software. This release enables quite a lot of new things to appear in const fn, two new standard library APIs, and one feature useful for library authors.

Empowering everyone to build reliable and efficient software.

The Rust team is happy to announce a new version of Rust, 1.46.0. Rust is a programming language that is empowering everyone to build reliable and efficient software.

If you have a previous version of Rust installed via rustup, getting Rust 1.46.0 is as easy as:

rustup update stable

If you don't have it already, you can get rustup from the appropriate page on our website, and check out the detailed release notes for 1.46.0 on GitHub.

What's in 1.46.0 stable

This release enables quite a lot of new things to appear in const fn, two new standard library APIs, and one feature useful for library authors. See the detailed release notes to learn about other changes not covered by this post.

const fn improvements

There are several core language features you can now use in a const fn:

  • if, if let, and match
  • while, while let, and loop
  • the && and || operators

You can also cast to a slice:

const fn foo() {
  let x = [1, 2, 3, 4, 5];

  // cast the array to a slice
  let y: &[_] = &x;
}

While these features may not feel new, given that you could use them all outside of const fn, they add a lot of compile-time computation power! As an example, the const-sha1 crate can let you compute SHA-1 hashes at compile time. This led to a 40x performance improvement in Microsoft's WinRT bindings for Rust.

#[track_caller]

Back in March, the release of Rust 1.42 introduced better error messages when unwrap and related functions would panic. At the time, we mentioned that the way this was implemented was not yet stable. Rust 1.46 stabilizes this feature.

This attribute is called #[track_caller], which was originally proposed in RFC 2091 way back in July of 2017! If you're writing a function like unwrap that may panic, you can put this annotation on your functions, and the default panic formatter will use its caller as the location in its error message. For example, here is unwrap previously:

pub fn unwrap(self) -> T {
    match self {
        Some(val) => val,
        None => panic!("called `Option::unwrap()` on a `None` value"),
    }
}

It now looks like this:

#[track_caller]
pub fn unwrap(self) -> T {
    match self {
        Some(val) => val,
        None => panic!("called `Option::unwrap()` on a `None` value"),
    }
}

That's it!

If you are implementing a panic hook yourself, you can use the caller method on std::panic::Location to get access to this information.

Library changes

Keeping with the theme of const fn improvements, std::mem::forget is now a const fn. Additionally, two new APIs were stabilized this release:

  • Option::zip
  • vec::Drain::as_slice

See the detailed release notes for more.

Other changes

There are other changes in the Rust 1.46.0 release: check out what changed in Rust, Cargo, and Clippy.

Contributors to 1.46.0

Many people came together to create Rust 1.46.0. We couldn't have done it without all of you. Thanks!

rust web-development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Important Reasons to Hire a Professional Web Development Company

    You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...

Web Design and Development Services

Get Best out from Web Design and Development Services from Vinew Technologies,We have a dedicated team of experienced and knowledgeable web developers, designers and testers. Therefore, we have proficiency in analyzing, developing and designing the necessity of intricate Website Development projects.

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

Custom Web Development Services | Vinew Technologies

Vinew Technologies is the leading Custom web development services company known for creating state of the art custom business websites that help you engage your audience better.