Skip to content

Commit 5933627

Browse files
committed
First draft of 1.36 announcement.
1 parent 101bc99 commit 5933627

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed

posts/2019-07-04-Rust-1.36.0.md

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

0 commit comments

Comments
 (0)