Rust 2021, the planned third edition of the Rust programming language due in October, is expected to significantly improve how Rust feels in practice, resulting from a number of small changes.
In a May 11 bulletin, the Rust 2021 edition working group cited changes including a new prelude to the standard library, which is the module containing everything automatically imported in every module. The new prelude will fix an issue in which adding a trait can subtly break code. This will be done with three additions:
Also in Rust 2021, the new feature resolver introduced in Rust 1.51 in March will become the default. This resolver no longer merges all requested features for crates that are depended on in multiple ways.
Other changes in the works for Rust 2021 include closures, anonymous functions that can automatically capture anything referred to from within their body, will only capture the fields they use. This resolves a programming issue involving the availability of structs.
Delving deeper, the
panic! () macro will be more consistent, no longer accepting arbitrary expressions as the only argument.
To make space for new syntax in the future, syntax will be reserved for prefixed identifiers and literals, including
prefix can be any identifier. Future prefixes might include
f”” as a shorthand for a format string, and
z”” for null-terminated C strings. Another possibility is
k”keyword, to allow writing keywords that do not exist yet.
Meanwhile, two existing lints,
ellipsis-inclusive-range-patterns, will become hard errors in Rust 2021.
Plans call for Rust 2021 Edition changes to make it into Rust 1.56.0, due in October. Editions of Rust serve as a mechanism to enable the release of features that would otherwise be backward incompatible, such as adding a keyword that would invalidate variables of the same name.
Rust editions are opt-in, so existing crates do not see the changes until they explicitly migrate over to the new edition. Crates compiled in one edition will seamlessly interoperate with crates compiled in other editions. The working group seeks to make it easy to upgrade crates to a new edition.