The Rust team has revealed new insights into what to expect from Rust 2021, which is scheduled to be released in October 2021. 

Rust 2021 is the third edition of the language. Editions in Rust are opt-in updates that introduce features that are backwards incompatible. Since they are opt-in, developers won’t see the changes unless they decide to migrate to that edition.

According to the team, crates in one edition are interoperable with crates compiled in a different edition. One change in this edition is a new prelude, which is a module that contains the things imported automatically in every module. Adding a trait to the prelude can break existing code, but as a workaround, Rust 2021 will include a new prelude that has three additions over the current one.

This edition will also introduce a small workaround to IntoIterator, which currently causes brakes to existing code. The Rust team explained.

“In Rust 2015 and 2018 code, the compiler will still resolve array.into_iter() to (&array).into_iter() like before, as if the trait implementation does not exist. This only applies to the .into_iter() method call syntax. It does not affect any other syntax such as for e in [1, 2, 3], iter.zip([1, 2, 3]) or IntoIterator::into_iter([1, 2, 3]). Those will start to work in all editions. While it’s a shame that this required a small hack to avoid breakage, we’re very happy with how this solution keeps the difference between the editions to an absolute minimum. Since the hack is only present in the older editions, there is no added complexity in the new edition,”

Rust 2021 will also introduce a new feature resolver that no longer merges all requested features in crates that are dependencies. Closures, which automatically capture whatever is referred to from within their body, will only capture the fields they actually use. The 2021 version will introduce a more consistent panic!() macro as well. The new macro won’t accept arbitrary expressions as their only argument. The release will also reserve some syntax to make space for new syntax down the line.

Finally, in Rust 1.53, patterns were extended to support | nested anywhere in the pattern, which enabled developers to write Some(1 | 2) instead of Some(1) | Some(2). This change affects macro_rules macros because they can accepted patterns using the :pat specifier, but :pat doesn’t match |. Starting in Rust 2021, the :pat fragment specifier will be able to match A | B.

These features are the final features that will be available in Rust 2021. They were decided upon by the Rust 2021 Working Group by meeting two criteria: 1) they had to be approved by the appropriate Rust team, and 2) their implementation had to have been far enough along that the group was confident in their ability to be completed in time for the planned milestones.

The Rust 2021 Working Group plans to have these changes merged and tested by September in order to ensure Rust 2021 can be added to Rust 1.56.0. Rust 1.56.0 will be in beta for six weeks and released as stable on October 21st.

Tags: , , , , , , , , , , , , , , , , , , , , ,