|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.22 (and 1.22.1)" |
| 4 | +author: The Rust Core Team |
| 5 | +--- |
| 6 | + |
| 7 | +The Rust team is happy to announce *two* new versions of Rust, 1.22.0 and |
| 8 | +1.22.1. Rust is a systems programming language focused on safety, speed, and |
| 9 | +concurrency. |
| 10 | + |
| 11 | +> Wait, two versions? At the last moment, we [discovered a a late-breaking |
| 12 | +> issue with the new macOS High |
| 13 | +> Sierra](https://github.com/rust-lang/rust/pull/46183) in 1.22.0, and for |
| 14 | +> various reasons, decided to release 1.22.0 as usual, but also put out a |
| 15 | +> 1.22.1 with the patch. The bug is actually in Cargo, not `rustc`, and only |
| 16 | +> affects users on macOS High Sierra. |
| 17 | +
|
| 18 | +If you have a previous version of Rust installed via rustup, getting Rust |
| 19 | +1.22.1 is as easy as: |
| 20 | + |
| 21 | +```bash |
| 22 | +$ rustup update stable |
| 23 | +``` |
| 24 | + |
| 25 | +If you don't have it already, you can [get `rustup`][install] from the |
| 26 | +appropriate page on our website, and check out the [detailed release notes for |
| 27 | +1.22.0][notes] and 1.22.1 on GitHub. |
| 28 | + |
| 29 | +[install]: https://www.rust-lang.org/install.html |
| 30 | +[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1220-2017-11-22 |
| 31 | + |
| 32 | +## What's in 1.22.0 and 1.22.1 stable |
| 33 | + |
| 34 | +The headline feature for this release is one many have been anticipating for |
| 35 | +a long time: you can now [use `?` with `Option<T>`]! About a year ago, in |
| 36 | +[Rust 1.13], we introduced the `?` operator for working with `Result<T, E>`. |
| 37 | +Ever since then, there's been discussion about how far `?` should go: should |
| 38 | +it stay only for results? Should it be user-extensible? Should it be |
| 39 | +usable with `Option<T>`? |
| 40 | + |
| 41 | +In Rust 1.22, basic usage of `?` with `Option<T>` is now stable. |
| 42 | +This code will now compile: |
| 43 | + |
| 44 | +```rust |
| 45 | +fn try_option_some() -> Option<u8> { |
| 46 | + let val = Some(1)?; |
| 47 | + Some(val) |
| 48 | +} |
| 49 | +assert_eq!(try_option_some(), Some(1)); |
| 50 | + |
| 51 | +fn try_option_none() -> Option<u8> { |
| 52 | + let val = None?; |
| 53 | + Some(val) |
| 54 | +} |
| 55 | +assert_eq!(try_option_none(), None); |
| 56 | +``` |
| 57 | + |
| 58 | +However, this functionality is still a bit limited; you cannot yet write |
| 59 | +code that mixes results and options with `?` in the same function, for |
| 60 | +example. This will be possible in the future, and already is in nightly |
| 61 | +Rust; expect to hear more about this in a future release. |
| 62 | + |
| 63 | +[use `?` with `Option<T>`]: https://github.com/rust-lang/rust/pull/42526 |
| 64 | +[Rust 1.13]: https://blog.rust-lang.org/2016/11/10/Rust-1.13.html |
| 65 | + |
| 66 | +Types that implement `Drop` are [now allowed in `const` and `static` |
| 67 | +items](https://github.com/rust-lang/rust/pull/44456). Like this: |
| 68 | + |
| 69 | +```rust |
| 70 | +struct Foo { |
| 71 | + a: u32 |
| 72 | +} |
| 73 | + |
| 74 | +impl Drop for Foo { |
| 75 | + fn drop(&mut self) {} |
| 76 | +} |
| 77 | + |
| 78 | +const F : Foo = Foo { a : 0 }; |
| 79 | +static S : Foo = Foo { a : 0 }; |
| 80 | +``` |
| 81 | + |
| 82 | +This change doesn't bring much on its own, but as we improve our |
| 83 | +ability to compute things at compile-time, more and more will be |
| 84 | +possible in `const` and `static`. |
| 85 | + |
| 86 | +Additionally, some small quality-of-life improvements: |
| 87 | + |
| 88 | +[Two] recent [compiler changes] should speed up compiles in debug mode. We |
| 89 | +don't have any specific numbers to commit to with these changes, but as |
| 90 | +always, compile times are very important to us, and we're continuing to |
| 91 | +work on improving them. |
| 92 | + |
| 93 | +[Two]: https://github.com/rust-lang/rust/pull/45075 |
| 94 | +[compiler changes]: https://github.com/rust-lang/rust/pull/45064 |
| 95 | + |
| 96 | +[`T op= &T` now works for primitive types][add], which is a fancy way of saying: |
| 97 | + |
| 98 | +```rust |
| 99 | +let mut x = 2; |
| 100 | +let y = &8; |
| 101 | + |
| 102 | +// this didn't work, but now does |
| 103 | +x += y; |
| 104 | +``` |
| 105 | + |
| 106 | +Previously, you'd have needed to write `x += *y` in order to de-reference, so |
| 107 | +this solves a small papercut. |
| 108 | + |
| 109 | +[add]: https://github.com/rust-lang/rust/pull/44287 |
| 110 | + |
| 111 | +[Backtraces are improved on MacOS](https://github.com/rust-lang/rust/pull/44251). |
| 112 | + |
| 113 | +You can now [create `compile-fail` tests in Rustdoc], like this: |
| 114 | + |
| 115 | +``` |
| 116 | +/// ```compile_fail |
| 117 | +/// let x = 5; |
| 118 | +/// x += 2; // shouldn't compile! |
| 119 | +/// ``` |
| 120 | +``` |
| 121 | + |
| 122 | +Please note that these kinds of tests can be more fragile than others, as |
| 123 | +additions to Rust may cause code to compile when it previously would not. |
| 124 | +Consider the first announcement with `?`, for example: that code would fail |
| 125 | +to compile on Rust 1.21, but compile successfully on Rust 1.22, causing your |
| 126 | +test suite to start failing. |
| 127 | + |
| 128 | +[create `compile-fail` tests in Rustdoc]: https://github.com/rust-lang/rust/pull/43949 |
| 129 | + |
| 130 | +Finally, we [removed support for the `le32-unknown-nacl` |
| 131 | +target](https://github.com/rust-lang/rust/pull/45041). Google itself [has |
| 132 | +deprecated |
| 133 | +PNaCl](https://blog.chromium.org/2017/05/goodbye-pnacl-hello-webassembly.html), |
| 134 | +instead throwing its support behind [WebAssembly](http://webassembly.org/). |
| 135 | +You can already compile Rust code to WebAssembly today, and you can expect |
| 136 | +to hear more developments regarding this in future releases. |
| 137 | + |
| 138 | +See the [detailed release notes][notes] for more. |
| 139 | + |
| 140 | +### Library stabilizations |
| 141 | + |
| 142 | +A few new APIs were stabilized this release: |
| 143 | + |
| 144 | +- [`Box<Error>` now impls `From<Cow<str>>`][44466] |
| 145 | +- [`std::mem::Discriminant` is now guaranteed to be `Send + Sync`][45095] |
| 146 | +- [`fs::copy` now returns the length of the main stream on NTFS.][44895] |
| 147 | +- [Properly detect overflow in `Instant += Duration`.][44220] |
| 148 | +- [impl `Hasher` for `{&mut Hasher, Box<Hasher>}`][44015] |
| 149 | +- [impl `fmt::Debug` for `SplitWhitespace`.][44303] |
| 150 | + |
| 151 | +[44466]: https://github.com/rust-lang/rust/pull/44466 |
| 152 | +[45095]: https://github.com/rust-lang/rust/pull/45095 |
| 153 | +[44895]: https://github.com/rust-lang/rust/pull/44895 |
| 154 | +[44220]: https://github.com/rust-lang/rust/pull/44220 |
| 155 | +[44015]: https://github.com/rust-lang/rust/pull/44015 |
| 156 | +[44303]: https://github.com/rust-lang/rust/pull/44303 |
| 157 | + |
| 158 | +See the [detailed release notes][notes] for more. |
| 159 | + |
| 160 | +### Cargo features |
| 161 | + |
| 162 | +If you have a big example to show your users, Cargo has grown |
| 163 | +the ability to [build multi-file |
| 164 | +examples](https://github.com/rust-lang/cargo/pull/4496) by |
| 165 | +creating a subdirectory inside `examples` that contains a |
| 166 | +`main.rs`. |
| 167 | + |
| 168 | +Cargo now has the ability to [vendor git repositories](https://github.com/rust-lang/cargo/pull/3992). |
| 169 | + |
| 170 | +See the [detailed release notes][notes] for more. |
| 171 | + |
| 172 | +## Contributors to 1.22.0 and 1.22.1 |
| 173 | + |
| 174 | +Many people came together to create Rust 1.22. We couldn't have done it |
| 175 | +without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.22.0) (and |
| 176 | +[Thanks again!](https://thanks.rust-lang.org/rust/1.22.1)) |
0 commit comments