Programming language: Public test phase for Rust 2021 has started


Two months after the first announcement of Rust 2021, the public test phase has now begun. Obviously, the features for the upcoming edition have been completely implemented in nightly builds, and anyone interested can try out the new features. In the words of the Rust blog, “We encourage adventurous users to test migrating their crates to Rust 2021” – Crates are the packages in the Rust universe.

Rust 2021 is the third edition of the programming language after Rust 2015 and Rust 2018. New editions introduce additional features that can lead to incompatibilities with the previous edition. However, the update should bring as few breaking changes as possible. Back then, in 2018, Rust had the async await pattern on board, which had the new keywords as a side effect async and await brought with me. This could become a problem when code used the previously unreserved terms as variable names, for example, which is seldom the case.

Since developers define the respective edition for each crate, they do not have to make any changes to older code in order to use it with source code for the latest edition. Finally, under the hood, the compiler creates a uniform internal representation for mixed code.

Among the innovations in Rust 2021, the heise Developer introduced in May, the extension of the automatic imports in the prelude of the standard library belong to std::convert::TryInto, std::convert::TryFrom and std::iter::FromIterator. In the new edition arrays and not just the references to them are the trait as before IntoIterator to implement.

In Rust 2021, closures only access the sub-objects actually used from the context. This corrects errors if, for example, another, unused part of a struct has been removed. The macro also processes panic! for output messages in the event of unexpected program termination, the first parameter as a format string such as println!. Finally, the edition reserves the syntax for identifiers as prefixes.

In the Documentation can be found in the instructions for converting projects to a new edition. For the upcoming Rust 2021, the procedure is a little different than when switching to a stable edition, as there are no builds from the release channel but from the Nightly Channel required are.

First, developers need to have the latest nightly build over rustup update nightly to install. Then they call cargo +nightly fix --edition on. The line cargo-features = ["edition2021"] above the [package]-Section stand. After all, the field for the edition applies edition = "2021" adapt.

You can then use the command cargo +nightly check test that the code works with the new edition. The documentation lists, among other things, the following short code snippet that uses an anonymous parameter:

trait Foo {
  fn foo(&self, i32);

The code can only be compiled with the upcoming edition, as Rust 2018 does not know any anonymous parameters.

More details on the test phase for Rust 2021 can be found on the Rust blog. The final release of the upcoming edition is planned for version 1.56 of the programming language, which is due to appear on October 21. Rust 1.53 is currently up to date, and new versions appear regularly every six weeks.


To home page