Rust 1.36.0 release: Future trait, alloc stabilization and MaybeUninit
I present to your attention a translation of the publication on the new version of everyone's favorite programming language Rust .
Introduction
The Rust programming language team is pleased to announce a new version, 1.36.0. Rust is a programming language that allows everyone to develop reliable and fast software.
If you installed the previous version of Rust using the tools rustup
, getting the current version will not be difficult:
$ rustup update stable
If you still do not have it rustup
, you can get it from the corresponding page on our website. A detailed review of this release is available on GitHub.
What is included in the stable version?
This release privnos many changes, including the long-awaited stabilization trait Future
, crate alloc
, structure , , new implementation and support of the flag in the Cargo.MaybeUninit
NLL для Rust 2015
HashMap
--offline
The most significant changes are described below, however you can also see a detailed list of innovations for additional awareness.
Future Stabilization
Rust 1.36.0 has stabilized the long-awaited трейт Future
!
We hope that this innovation will allow the popular crates, libraries, and the ecosystem as a whole to prepare for the async
/ syntax .await
, stabilization of which is planned for the near future.
Distrib rack stabilization
Prior to version 1.36.0, the standard library consisted of crates std
, core
and proc_macro
. Crate core
had basic functionality (such as Iterator
and Copy
) and could be used in environments #![no_std]
, so it does not impose any demands. Meanwhile, the crate std
supplied such types as , as well as the functionality of the operating system (global allocator).Box
Starting with Rust 1.36.0, the crate components std
dependent on the global allocator, for example, are now available in the crate . The crate , meanwhile, re-exports these components.Vec
alloc
std
While c programs #![no_std]
using crate alloc
still require a channel nightly
, c libraries #![no_std]
can use crate alloc
in stable Rust.
Also note that all "normal" programs (without #![no_std]
) in their dependencies are able to contain the libraries described above with #![no_std]
. We hope that this will contribute to the development of an ecosystem compatible with #![no_std]
.
If you are a developer of a library that requires allocation primitives to function, we recommend marking your library as compatible with #![no_std]
using the following syntax at the beginning of the file lib.rs
:
#![no_std]
extern crate alloc;
use alloc::vec::Vec;
MaybeUninit place mem :: uninitialized
In previous releases of Rust, the function mem::uninitialized
allowed you to cancel initialization checks because it believed that you ALREADY performed type initialization T
without doing anything. One of the uses of this function was the "lazy" allocation of arrays.
However, it mem::uninitalized
is an overly dangerous operation that cannot be used correctly with the Rust compiler, assuming that all values are initialized properly.
For example, a call will immediately cause undefined behavior , since from the point of view of Rust, uninitialized bits are either zero ( ) or unit ( ), and only two of the above patterns are suitable for the type .mem::uninitialized::
false
true
bool
To resolve this situation, in Rust 1.36.0, the type was stabilized . The Rust compiler no longer assumes that it is an initialized type . Thus, you can perform gradual initialization more safely and finally use it when you are sure that it contains an initialized type .MaybeUninit
MaybeUninit
T
.assume_init()
maybe_t: MaybeUninit
T
Since it is a safer alternative, starting with Rust 1.38, the function will be marked obsolete.MaybeUninit
mem::uninitialized
To learn more about uninitialized memory, mem::uninitialized
and read the article by Alexis Bessessner . The standard library also contains ample documentation about .MaybeUninit
MaybeUninit
NLL for Rust 2015
In the announcement of Rust 1.31.0, we told you about NLL (non-lexical life timelines), an innovation in the language that makes the link controller (borrow checker) smarter and friendlier. For example, now you can write like this:
fn main() {
let mut x = 5;
let y = &x;
let z = &mut x; // Не было разрешено до 1.31.0
}
At 1.31.0, the NLL was stabilized only for Rust 2018, and it was assumed that we would transfer it to Rust 2015 in the future. This was done in Rust 1.36.0, NLL became available for Rust 2015.
With NLL supported in both versions, we are approaching the removal of the old link controller. However, the old link controller, unfortunately, accepted incorrect code , which it should NOT have accepted.
And, as a result, NLL is now at the “migration” stage, in which we will issue warnings instead of errors if the NLL link controller does not approve the code that would approve the old AST- based link controller . We advise you to look at the list of affected public crates .
To learn more about NLL, MIR, how to fix related integrity issues, and what can be done with the compiler warnings that appear, read Felix Klok’s article .
New HashMap Implementation
In Rust 1.36.0, the previous implementation was replaced by a crate based implementation based on the SwissTable design . The interface remains the same, but the current implementation is on average faster and consumes less memory. However, note that the standard implementation still uses the SipHash 1-3 algorithm .HashMap
hashbrown
- Offline support in Cargo
During most builds, Cargo does not use your network. However, at some points, for example, when a new dependency was added, Cargo will still try to access the network. Sometimes this behavior is unacceptable (in an isolated system or in an airplane).
Rust 1.36.0 has stabilized the new flag --offline
. This flag overrides the dependency resolution algorithm, instead using local cached dependencies.
If the requested crates are not available without a network that has been disconnected, then Cargo will exit with an error. To pre-populate the local cache before leaving the network, use the command cargo fetch
that downloads all the necessary dependencies for a specific project.
To learn more about --offline
and cargo fetch
, read Nick Cameron's article . Other changes to Cargo are described in detail here .
Library changes
The macro
dbg!
began to support multiple arguments;Some methods have become constant:
Some APIs are stabilized, including:
task::Waker
andtask::Poll
VecDeque::rotate_left
andVecDeque::rotate_right
Read::read_vectored
andWrite::write_vectored
Iterator::copied
BorrowMut
forString
str::as_mut_ptr
Other changes
Detailed change descriptions in version 1.36.0 are available for Rust , the standard library , Cargo and Clippy .
Members 1.36.0
A lot of people came together to create Rust 1.36.0. We could not have done this without all of you, thanks !
From translator
With any questions on the Rust language, they will be able to help you in the Russian-language Telegram chat or in a similar chat for newcomers .