Rust 1.42.0 adds subslice patterns and improved panic messaging

Share
  • March 13, 2020

The newest version of Rust is now generally available. Version 1.42.0 stable arrived on March 12, 2020,

As usual with all new Rust releases, you can easily update to the latest version via rustup with:

$ rustup update stable


This release arrives less than three months after the previous release. Rust is always on the move with new features, changes, and improvements so let’s keep up with the pace and see what’s new. According to this-week-in-rust.org, there were 302 merged pull requests during the week of March 10, 2020.

Here are some of the highlights:

SEE ALSO: 90% of remote workers would recommend it to a friend

Improved error messaging

Previously, when calling unwrap() on an Option::None value, Rust produced an error message that wasn’t always helpful and didn’t provide enough location information.

Now, the panic message is a little more developer-friendly and shows which line the invalid call to unwrap is located.

Before (1.41.0)

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /.../src/libcore/macros/mod.rs:15:40

After (1.42.0)

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/main.rs:2:5

The new message shows that the error is on line 2 of src/main.rs. View and track the original discussion of this on GitHub.

Introducing subslice patterns

Slice patterns allow users to match on slices. Now, 1.42 adds support for matching on parts of a slice.

From a blog post by Mazdak “Centril” Farrokhzad:

In Rust 1.42.0, we are stabilizing subslice patterns. To introduce a subslice pattern, we use .. which denotes a variable-length gap, matching as many elements as possible not matched by the patterns before and after the ...

We can also bind a subslice to a variable. For example, suppose we want to disallow ... in all but the last parameter of a function.

According to Farrokhzad’s blog post, stable subslice patterns are more than 7 years in the making!

Deprecations and downgrades

The Error::description method is now deprecated. It has been “soft deprecated” since Rust 1.27 when it was de-emphasized in the official documentation. Now, it is officially deprecated, although due to Rust’s stability policy, it will not be officially removed. See the pull request for more information.

Since Apple no longer supports 32-bit targets, Rust has officially downgraded them to Tier 3 support in 1.42.0. Tier 3 support means that they will not be available for download using rustup and will be ignored during automatic builds. From now on, users will have to build from the source and may encounter errors and bugs.

SEE ALSO: PHP is very much alive and doesn’t plan on dying

Misc. Rust 1.42.0 changes

Additional changes include:

The post Rust 1.42.0 adds subslice patterns and improved panic messaging appeared first on JAXenter.

Source : JAXenter