What to expect in Rust 2021

by Joseph K. Clark

The Rust team has revealed new insight 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 backward incompatible features. Since they are opt-in, developers won’t see the changes unless they migrate to that edition. According to the team, crates in one edition are interoperable with bins compiled in a different edition. “This ensures that the decision to migrate to a newer edition is a ‘private one’ that the crate can make without affecting others,” the Rust team wrote in a blog post.

One change being made in this edition is a new intro, which is a module that contains the things imported automatically in every module. Adding a trait to the opening can break existing code, but as a workaround, Rust 2021 will include a new intro that has three additions over the current one: std::convert::TryInto, std::convert::TryFrom, and std::iter::FromIterator. 

This edition will also introduce a small workaround to IntoIterator, which currently causes breaks to existing code. “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 called 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 delighted with how this solution keeps the difference between the editions to an absolute minimum. Since the hack is only present in the older editions, the new edition has no added complexity,” the Rust team explained.

Rust 2021

Rust 2021 will also introduce a new feature resolver that no longer merges all requested features in crates that are dependencies. In the latest edition, closures automatically capture whatever is referred to from within their body and will only charge the fields they use. Rust 2021 will introduce a more consistent panic! () macro as well. The new macro won’t accept arbitrary expressions as their only argument. 

This release will also reserve some syntax to make space for the new syntax. It will secure prefix#identifier,” string”, prefixes, and #123. In addition, it will create two existing lines problematic errors instead of just warnings as they are currently. The keyword Dyn to identify trait objects will be mandatory, and the deprecated … syntax for inclusive range patterns won’t be accepted anymore. 

Finally, in Rust 1.53, patterns were extended to support | nested anywhere in the way, which enabled developers to write Some(1 | 2) instead of Some(1) | Some(2). This change affects macro_rules macros because they can accept patterns using the: pat specifier, but: pat doesn’t match |. Starting in Rust 2021, the: pat fragment specifier will be able to reach 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 merge and test these changes by September 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. It will release another announcement on the new edition in July, when all changes should be implemented and ready for testing. 

Related Posts