|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.36.0" |
| 4 | +author: The Rust Release Team |
| 5 | +release: true |
| 6 | +--- |
| 7 | + |
| 8 | +The Rust team is happy to announce a new version of Rust, 1.36.0. |
| 9 | +Rust is a programming language that is empowering everyone to build reliable and efficient software. |
| 10 | + |
| 11 | +If you have a previous version of Rust installed via rustup, getting Rust 1.36.0 is as easy as: |
| 12 | + |
| 13 | +```console |
| 14 | +$ rustup update stable |
| 15 | +``` |
| 16 | + |
| 17 | +If you don't have it already, you can [get `rustup`][install] from the appropriate page on our website, |
| 18 | +and check out the [detailed release notes for 1.36.0][notes] on GitHub. |
| 19 | + |
| 20 | +[install]: https://www.rust-lang.org/install.html |
| 21 | +[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1360-2019-07-04 |
| 22 | + |
| 23 | +## What's in 1.36.0 stable |
| 24 | + |
| 25 | +This release brings many changes, including the stabilization of the [`Future`] trait, |
| 26 | +the [`alloc`][alloc-crate] crate, the [`MaybeUninit<T>`] type, [NLL for Rust 2015][felix-blog], |
| 27 | +a new `HashMap<K, V>` implementation, and [`--offline`] support in Cargo. |
| 28 | +Read on for a few highlights, or see the [detailed release notes][notes] for additional information. |
| 29 | + |
| 30 | +### The [`Future`] is here! |
| 31 | + |
| 32 | +[`Future`]: https://doc.rust-lang.org/std/future/trait.Future.html |
| 33 | +[pr-future]: https://github.com/rust-lang/rust/pull/59739 |
| 34 | + |
| 35 | +In Rust 1.36.0 the long awaited [`Future`] trait has been [stabilized][pr-future]! |
| 36 | + |
| 37 | +With this stabilization, we hope to give important crates, libraries, |
| 38 | +and the ecosystem time to prepare for `async` / `.await`, |
| 39 | +which we'll tell you more about in the future. |
| 40 | + |
| 41 | +### The [`alloc`][alloc-crate] crate is stable |
| 42 | + |
| 43 | +[alloc-crate]: https://doc.rust-lang.org/alloc/index.html |
| 44 | + |
| 45 | +Before 1.36.0, the standard library consisted of the crates `std`, `core`, and `proc_macro`. |
| 46 | +The `core` crate provided core functionality such as `Iterator` and `Copy` |
| 47 | +and could be used in `#![no_std]` environments since it did not impose any requirements. |
| 48 | +Meanwhile, the `std` crate provided types like `Box<T>` and OS functionality |
| 49 | +but required a global allocator and other OS capabilities in return. |
| 50 | + |
| 51 | +Starting with Rust 1.36.0, the parts of `std` that depend on a global allocator, e.g. `Vec<T>`, |
| 52 | +are now available in the `alloc` crate. The `std` crate then re-exports these parts. |
| 53 | +While `#![no_std]` binaries using `alloc` still require nightly Rust, |
| 54 | +`#![no_std]` library crates can use the `alloc` crate in stable Rust. |
| 55 | +Meanwhile, normal binaries, without `#![no_std]`, can depend on such library crates. |
| 56 | +We hope this will facilitate the development of a `#![no_std]` compatible ecosystem of libraries |
| 57 | +prior to stabilizing support for `#![no_std]` binaries using `alloc`. |
| 58 | + |
| 59 | +If you are the maintainer of a library that only relies on some allocation primitives to function, |
| 60 | +consider making your library `#[no_std]` compatible by using the following at the top of your `lib.rs` file: |
| 61 | + |
| 62 | +```rust |
| 63 | +#![no_std] |
| 64 | + |
| 65 | +extern crate alloc; |
| 66 | + |
| 67 | +use alloc::vec::Vec; |
| 68 | +``` |
| 69 | + |
| 70 | +### [`MaybeUninit<T>`] instead of [`mem::uninitialized`] |
| 71 | + |
| 72 | +[`MaybeUninit<T>`]: https://doc.rust-lang.org/std/mem/union.MaybeUninit.html |
| 73 | +[`mem::uninitialized`]: https://doc.rust-lang.org/std/mem/fn.uninitialized.html |
| 74 | +[gankro-blog]: https://gankro.github.io/blah/initialize-me-maybe/ |
| 75 | +[pr-60445]: https://github.com/rust-lang/rust/pull/60445 |
| 76 | + |
| 77 | +In previous releases of Rust, the [`mem::uninitialized`] function has allowed you to bypass Rust's |
| 78 | +initialization checks by pretending that you've initialized a value at type `T` without doing anything. |
| 79 | +One of the main uses of this function has been to lazily allocate arrays. |
| 80 | + |
| 81 | +However, [`mem::uninitialized`] is an incredibly dangerous operation that essentially |
| 82 | +cannot be used correctly as the Rust compiler assumes that values are properly initialized. |
| 83 | +For example, calling `mem::uninitialized::<bool>()` causes *instantaneous __undefined behavior__* |
| 84 | +as, from Rust's point of view, the uninitialized bits are neither `0` (for `false`) |
| 85 | +nor `1` (for `true`) -- the only two allowed bit patterns for `bool`. |
| 86 | + |
| 87 | +To remedy this situation, in Rust 1.36.0, the type [`MaybeUninit<T>`] has been [stabilized][pr-60445]. |
| 88 | +The Rust compiler will understand that it should not assume that a [`MaybeUninit<T>`] is a properly initialized `T`. |
| 89 | +Therefore, you can do gradual initialization more safely and eventually use `.assume_init()` |
| 90 | +once you are certain that `maybe_t: MaybeUninit<T>` contains an initialized `T`. |
| 91 | + |
| 92 | +As [`MaybeUninit<T>`] is the safer alternative, starting with Rust 1.38, |
| 93 | +the function [`mem::uninitialized`] will be deprecated. |
| 94 | + |
| 95 | +To find out more about uninitialized memory, [`mem::uninitialized`], |
| 96 | +and [`MaybeUninit<T>`], read [Alexis Beingessner's blog post][gankro-blog]. |
| 97 | +The standard library also contains extensive documentation about [`MaybeUninit<T>`]. |
| 98 | + |
| 99 | +### NLL for Rust 2015 |
| 100 | + |
| 101 | +[nll-2018]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#non-lexical-lifetimes |
| 102 | +[soundness]: https://en.wikipedia.org/wiki/Soundness |
| 103 | +[felix-blog]: http://blog.pnkfx.org/blog/2019/06/26/breaking-news-non-lexical-lifetimes-arrives-for-everyone/ |
| 104 | +[crater-nll]: https://github.com/rust-lang/rust/issues/60680#issuecomment-495089654 |
| 105 | + |
| 106 | +[In the announcement for Rust 1.31.0][nll-2018], we told you about NLL (Non-Lexical Lifetimes), |
| 107 | +an improvement to the language that makes the borrow checker smarter and more user friendly. |
| 108 | +For example, you may now write: |
| 109 | + |
| 110 | +```rust |
| 111 | +fn main() { |
| 112 | + let mut x = 5; |
| 113 | + let y = &x; |
| 114 | + let z = &mut x; // This was not allowed before 1.31.0. |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +In 1.31.0 NLL was stabilized only for Rust 2018, |
| 119 | +with a promise that we would backport it to Rust 2015 as well. |
| 120 | +With Rust 1.36.0, we are happy to announce that we have done so! NLL is now available for Rust 2015. |
| 121 | + |
| 122 | +With NLL on both editions, we are closer to removing the old borrow checker. |
| 123 | +However, the old borrow checker unfortunately accepted some [unsound][soundness] code it should not have. |
| 124 | +As a result, NLL is currently in a "migration mode" wherein we will emit warnings instead |
| 125 | +of errors if the NLL borrow checker rejects code the old AST borrow checker would accept. |
| 126 | +Please see [this list][crater-nll] of public crates that are affected. |
| 127 | + |
| 128 | +To find out more about NLL, MIR, the story around fixing soundness holes, |
| 129 | +and what you can do about the warnings if you have them, read [Felix Klock's blog post][felix-blog]. |
| 130 | + |
| 131 | +### A new [`HashMap<K, V>`] implementation |
| 132 | + |
| 133 | +[`hashbrown`]: https://crates.io/crates/hashbrown |
| 134 | +[`HashMap<K, V>`]: https://doc.rust-lang.org/std/collections/struct.HashMap.html |
| 135 | +[pr-hashbrown]: https://github.com/rust-lang/rust/pull/58623 |
| 136 | +[SwissTable]: https://abseil.io/blog/20180927-swisstables |
| 137 | +[pr-hashbrown-perf]: https://perf.rust-lang.org/compare.html?start=b57fe74a27590289fd657614b8ad1f3eac8a7ad2&end=abade53a649583e40ed07c26ee10652703f09b58&stat=wall-time |
| 138 | + |
| 139 | +In Rust 1.36.0, the `HashMap<K, V>` implementation has been [replaced][pr-hashbrown] |
| 140 | +with the one in the [`hashbrown`] crate which is based on the [SwissTable] design. |
| 141 | +While the interface is the same, the `HashMap<K, V>` implementation is now |
| 142 | +[faster on average][pr-hashbrown-perf] and has lower memory overhead. |
| 143 | +Note that unlike the `hashbrown` crate, |
| 144 | +the implementation in `std` still defaults to the SipHash 1-3 hashing algorithm. |
| 145 | + |
| 146 | +### [`--offline`] support in Cargo |
| 147 | + |
| 148 | +[`--offline`]: https://doc.rust-lang.org/cargo/commands/cargo-build.html#cargo_build_manifest_options |
| 149 | +[`cargo fetch`]: https://doc.rust-lang.org/cargo/commands/cargo-fetch.html |
| 150 | +[nrc-blog]: https://www.ncameron.org/blog/cargo-offline/ |
| 151 | +[relnotes-cargo]: https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-136-2019-07-04 |
| 152 | + |
| 153 | +During most builds, Cargo doesn't interact with the network. |
| 154 | +Sometimes, however, Cargo has to. |
| 155 | +Such is the case when a dependency is added and the latest compatible version needs to be downloaded. |
| 156 | +At times, network access is not an option though, for example on an airplane or in isolated build environments. |
| 157 | + |
| 158 | +In Rust 1.36, a new Cargo flag has been stabilized: [`--offline`]. |
| 159 | +The flag alters Cargo's dependency resolution algorithm to only use locally cached dependencies. |
| 160 | +When the required crates are not available offline, and a network access would be required, |
| 161 | +Cargo will exit with an error. |
| 162 | +To prepopulate the local cache in preparation for going offline, |
| 163 | +use the [`cargo fetch`] command, which downloads all the required dependencies for a project. |
| 164 | + |
| 165 | +To find out more about [`--offline`] and [`cargo fetch`], read [Nick Cameron's blog post][nrc-blog]. |
| 166 | + |
| 167 | +For information on other changes to Cargo, see the [detailed release notes][relnotes-cargo]. |
| 168 | + |
| 169 | +### Library changes |
| 170 | + |
| 171 | +[`dbg!`]: https://doc.rust-lang.org/std/macro.dbg.html |
| 172 | + |
| 173 | +The [`dbg!`] macro now supports multiple arguments. |
| 174 | + |
| 175 | +Additionally, a number of APIs have been made `const`: |
| 176 | + |
| 177 | +[`Layout::from_size_align_unchecked`]: https://doc.rust-lang.org/core/alloc/struct.Layout.html#method.from_size_align_unchecked |
| 178 | +[`mem::needs_drop`]: https://doc.rust-lang.org/std/mem/fn.needs_drop.html |
| 179 | +[`NonNull::dangling`]: https://doc.rust-lang.org/std/ptr/struct.NonNull.html#method.dangling |
| 180 | +[`NonNull::cast`]: https://doc.rust-lang.org/std/ptr/struct.NonNull.html#method.cast |
| 181 | + |
| 182 | +- [`Layout::from_size_align_unchecked`] |
| 183 | +- [`mem::needs_drop`] |
| 184 | +- [`NonNull::dangling`] |
| 185 | +- [`NonNull::cast`] |
| 186 | + |
| 187 | +New APIs have become stable, including: |
| 188 | + |
| 189 | +[`Iterator::copied`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.copied |
| 190 | +[`VecDeque::rotate_left`]: https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.rotate_left |
| 191 | +[`VecDeque::rotate_right`]: https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.rotate_right |
| 192 | +[`BorrowMut<str> for String`]: https://github.com/rust-lang/rust/pull/60404 |
| 193 | +[`str::as_mut_ptr`]: https://doc.rust-lang.org/std/primitive.str.html#method.as_mut_ptr |
| 194 | +[`pointer::align_offset`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.align_offset |
| 195 | +[`Read::read_vectored`]: https://doc.rust-lang.org/std/io/trait.Read.html#method.read_vectored |
| 196 | +[`Write::write_vectored`]: https://doc.rust-lang.org/std/io/trait.Write.html#method.write_vectored |
| 197 | +[`task::Waker`]: https://doc.rust-lang.org/std/task/struct.Waker.html |
| 198 | +[`task::Poll`]: https://doc.rust-lang.org/std/task/enum.Poll.html |
| 199 | + |
| 200 | +- [`task::Waker`] and [`task::Poll`] |
| 201 | +- [`VecDeque::rotate_left`] and [`VecDeque::rotate_right`] |
| 202 | +- [`Read::read_vectored`] and [`Write::write_vectored`] |
| 203 | +- [`Iterator::copied`] |
| 204 | +- [`BorrowMut<str> for String`] |
| 205 | +- [`str::as_mut_ptr`] |
| 206 | + |
| 207 | +Other library changes are available in the [detailed release notes][notes]. |
| 208 | + |
| 209 | +### Other changes |
| 210 | + |
| 211 | +[relnotes-clippy]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-136 |
| 212 | + |
| 213 | +Detailed 1.36.0 release notes are available for [Rust][notes], |
| 214 | +[Cargo][relnotes-cargo], and [Clippy][relnotes-clippy]. |
| 215 | + |
| 216 | +## Contributors to 1.36.0 |
| 217 | + |
| 218 | +Many people came together to create Rust 1.36.0. We couldn't have done it |
| 219 | +without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.36.0/) |
0 commit comments