Rust 1.42.0 adds subslice patterns and improved panic messaging
The Rust dev team has been hard at work. Less than three months after the previous release, Rust version 1.42.0 stable is here. This update introduces some new features such as subslice patterns, and better panic messages when unwrapping. Rustaceans, come and see what the newest highlights are.
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
We’re happy to announce the release of Rust 1.42.0, featuring better panic messages when unwrapping, subslice patterns, and more! Check out the highlights on our blog: https://t.co/necOsWRaHG
— Rust Language (@rustlang) March 12, 2020
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:
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.
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /.../src/libcore/macros/mod.rs:15:40
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.
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
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.
Misc. Rust 1.42.0 changes
Additional changes include:
- New macro: The new
matches!macro accepts an expression and a pattern. If the pattern matches the expression, it returns true.
- Various stabilized APIs: CondVar::wait_while & CondVar::wait_timeout_while, DebugMap::key & DebugMap::value, ManuallyDrop::take, ptr::slice_from_raw_parts_mut, and ptr::slice_from_raw_parts
- Cargo 1.42 updates
- Clippy updates