📜 ⬆️ ⬇️

Release Rust 1.36.0: Trey Future, stabilization alloc and MaybeUninit

I present to your attention the translation of the publication of the new version of the beloved programming language Rust .


Introduction


The Rust programming language development 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 rustup tools, getting the current version will not be difficult:


 $ rustup update stable 

If you still have no rustup , you can get it from the corresponding page on our site. A detailed review of this release is available on GitHub.


What is included in the stable version?


This release introduced many changes, including stabilization of the long-awaited Future trait, alloc alloc , MaybeUninit<T> structure, NLL Rust 2015 , new HashMap<K, V> implementation HashMap<K, V> and support for the --offline flag in Cargo.


The most significant changes are described below, but you can also see a detailed list of innovations for additional awareness.


Stabilization of the Future trait


Rust 1.36.0 stabilized long-awaited Future !


We hope that this innovation will allow popular crate, libraries and the whole ecosystem to prepare for the syntax async / .await , which is planned to stabilize for the near future.


Allocate crate stabilization


Prior to version 1.36.0, the standard library consisted of std , core and proc_macro . Coret core had basic functionality (such as Iterator and Copy ) and could be used in environments with #![no_std] , since it did not impose any requirements. Meanwhile, the std crate supplied such types as Box<T> , as well as operating system functionality (global allocator).


Starting with Rust 1.36.0, std crate components that are dependent on the global allocator, for example, Vec<T> , are now available in the alloc alloc . The crate std , meanwhile, re-exports these components.


While programs with #![no_std] using the alloc crate still require a nightly channel, libraries with #![no_std] can use the 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 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 #![no_std] , using the following syntax at the beginning of the lib.rs file:


 #![no_std] extern crate alloc; use alloc::vec::Vec; 

MaybeUninit mem place :: uninitialized


In previous releases of Rust, the mem::uninitialized function allowed you to cancel initialization checks, because you thought that you ALREADY performed type T initialization without doing anything. One use of this function was the "lazy" allocation of arrays.


However, mem::uninitalized is an overly dangerous operation that cannot be properly used with the Rust compiler, which assumes that all values ​​are initialized properly.


For example, a call to mem::uninitialized::<bool>() will immediately cause undefined behavior , since from the Rust point of view, the uninitialized bits are either zero ( false ) or one ( true ), and only the two patterns described above are suitable for the bool type .


To resolve this situation, the MaybeUninit<T> type was stabilized in Rust 1.36.0. The compiler Rust now does not assume that MaybeUninit<T> is an initialized type of T Thereby, you can perform stepwise initialization more safely and finally use .assume_init() when you are sure that maybe_t: MaybeUninit<T> contains the initialized type T


Since MaybeUninit<T> is a safer alternative, starting with Rust 1.38, the mem::uninitialized function will be marked obsolete.


To learn more about uninitialized memory, mem::uninitialized and MaybeUninit<T> , read Alexis Bessessner's article . The standard library also contains sufficient documentation for MaybeUninit<T> .


NLL for Rust 2015


In the announcement of Rust 1.31.0, we told you about NLL (non-lexical liftime), innovation in the language, which makes the reference 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, NLL was stabilized only for Rust 2018, and it was assumed that we would transfer it to Rust 2015 in the future. It was made 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 been 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 code that would approve the old AST link controller. We advise you to look at the list of affected public crate .


To learn more about NLL, MIR, about fixing related integrity issues, and what can be done with the compiler warnings that appear, read the article by Felix Klock .


New HashMap implementation


In Rust 1.36.0, the previous implementation of HashMap<K, V> was replaced by the implementation of the hashbrown hashbrown based on the SwissTable design. The interface remains the same, but the current implementation is on average faster and consumes less memory. Note, however, that the standard implementation still uses the SipHash 1-3 algorithm.


--Offline support in Cargo


During most builds, Cargo does not use your network. However, in some moments, for example, when a new dependency was added, Cargo will still try to gain access to the network. Sometimes this behavior is unacceptable (in an isolated system or on an airplane).


Rust 1.36.0 stabilized the new flag - --offline . This flag overrides the dependency resolution algorithm, using local cached dependencies instead.


If the requested crate is not available without a network that has been shut down, then Cargo will terminate with an error. To pre-populate the local cache before leaving the network, use the cargo fetch command, which loads 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 detailed here .


Changes in the library



Other changes


Detailed descriptions of changes in version 1.36.0 are available for Rust , Standard Library , Cargo and Clippy .


Members 1.36.0


Many people gathered together to create Rust 1.36.0. We could not have done this without all of you, thank you !


From translator


With any questions about the Rust language, they will be able to help you in the Russian-language Telegram chat or in a similar chat for newcomers .



')

Source: https://habr.com/ru/post/458848/


All Articles