The Rust 2021 edition, the upcoming third iteration of the Rust programming language, is set for release in October and promises to refine the developer experience by addressing several subtle yet impactful changes. These improvements are designed to make working with Rust feel more intuitive and seamless, enhancing the overall experience for developers using the language in practice.
One of the key updates in Rust 2021 involves a new prelude to the standard library. The prelude, which automatically imports modules in every file, will undergo adjustments to fix a longstanding issue where adding a trait could unintentionally break code. This issue will be resolved by introducing three important additions: std::convert::TryInto
, std::convert::TryFrom
, and std::iter::FromIterator
, all of which aim to simplify and stabilize the language’s behavior when working with traits and conversions.
Additionally, Rust 2021 will make the feature resolver, which was introduced in Rust 1.51, the default behavior. This feature resolver improves how crates are handled when they are depended on in multiple ways by no longer merging requested features across these crates, leading to clearer and more predictable builds. This adjustment is expected to streamline the way developers manage their dependencies and features.
Several other enhancements are also coming in Rust 2021, including changes to closures. Closures, which automatically capture variables from their surrounding environment, will now only capture the fields they actually use. This update resolves a common issue related to struct availability and improves performance. Other changes include a more consistent panic!()
macro, the reservation of new syntax for future use, and stricter error handling with two existing lints becoming hard errors. These updates reflect the ongoing effort to future-proof Rust, with the edition changes planned to be included in Rust 1.56.0. Editions allow Rust to introduce these kinds of improvements without breaking backward compatibility, making it easier for developers to adopt new features safely.