Announcing Rust 1.22 (and 1.22.1)

Nov. 22, 2017 ยท The Rust Core Team

The Rust team is happy to announce two new versions of Rust, 1.22.0 and 1.22.1. Rust is a systems programming language focused on safety, speed, and concurrency.

Wait, two versions? At the last moment, we discovered a late-breaking issue with the new macOS High Sierra in 1.22.0, and for various reasons, decided to release 1.22.0 as usual, but also put out a 1.22.1 with the patch. The bug is actually in Cargo, not rustc, and only affects users on macOS High Sierra.

If you have a previous version of Rust installed via rustup, getting Rust 1.22.1 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.22.0 and 1.22.1 on GitHub.

What's in 1.22.0 and 1.22.1 stable

The headline feature for this release is one many have been anticipating for a long time: you can now use ? with Option<T>! About a year ago, in Rust 1.13, we introduced the ? operator for working with Result<T, E>. Ever since then, there's been discussion about how far ? should go: should it stay only for results? Should it be user-extensible? Should it be usable with Option<T>?

In Rust 1.22, basic usage of ? with Option<T> is now stable. This code will now compile:

fn add_one_to_first(list: &[u8]) -> Option<u8> {
    // get first element, if exists
    // return None if it doesn't
    let first = list.get(0)?;
    Some(first + 1)
}

assert_eq!(add_one_to_first(&[10, 20, 30]), Some(11));
assert_eq!(add_one_to_first(&[]), None);

However, this functionality is still a bit limited; you cannot yet write code that mixes results and options with ? in the same function, for example. This will be possible in the future, and already is in nightly Rust; expect to hear more about this in a future release.

Types that implement Drop are now allowed in const and static items. Like this:

struct Foo {
    a: u32,
}

impl Drop for Foo {
    fn drop(&mut self) {}
}

const F: Foo = Foo { a: 0 };
static S: Foo = Foo { a: 0 };

This change doesn't bring much on its own, but as we improve our ability to compute things at compile-time, more and more will be possible in const and static.

Additionally, some small quality-of-life improvements:

Two recent compiler changes should speed up compiles in debug mode. We don't have any specific numbers to commit to with these changes, but as always, compile times are very important to us, and we're continuing to work on improving them.

T op= &T now works for primitive types, which is a fancy way of saying:

let mut x = 2;
let y = &8;

// this didn't work, but now does
x += y;

Previously, you'd have needed to write x += *y in order to de-reference, so this solves a small papercut.

Backtraces are improved on MacOS.

You can now create compile-fail tests in Rustdoc, like this:

/// ```compile_fail
/// let x = 5;
/// x += 2; // shouldn't compile!
/// ```

Please note that these kinds of tests can be more fragile than others, as additions to Rust may cause code to compile when it previously would not. Consider the first announcement with ?, for example: that code would fail to compile on Rust 1.21, but compile successfully on Rust 1.22, causing your test suite to start failing.

Finally, we removed support for the le32-unknown-nacl target. Google itself has deprecated PNaCl, instead throwing its support behind WebAssembly. You can already compile Rust code to WebAssembly today, and you can expect to hear more developments regarding this in future releases.

See the detailed release notes for more.

Library stabilizations

A few new APIs were stabilized this release:

See the detailed release notes for more.

Cargo features

If you have a big example to show your users, Cargo has grown the ability to build multi-file examples by creating a subdirectory inside examples that contains a main.rs.

Cargo now has the ability to vendor git repositories.

See the detailed release notes for more.

Contributors to 1.22.0 and 1.22.1

Many people came together to create Rust 1.22. We couldn't have done it without all of you. Thanks! (and Thanks again!)