Editions

The concept of editions was introduced in 2018 to allow stability without stagnation. They provide a way to make changes to the language that would otherwise be backwards incompatible, which would violate Rust's stability guarantees. Editions permit changes to syntax and semantics, but not the standard library of Rust. Because editions are opt-in on a per-crate basis and can interoperate with each other, there is no risk of an ecosystem split.

Technical details
When compiling a crate, the Rust compiler transforms the code into different intermediate representations (IRs) before generating the final machine code. The AST (abstract syntax tree) is first transformed to the HIR (high-level IR), then the MIR (mid-level IR) and then the LLVM IR. While the AST and HIR depends on the edition (for example, is a valid identifier only in the 2015 edition), the same MIR is used for all editions. This is what allows different editions to interoperate seamlessly.

One compiler can compile all editions; the edition is just a compiler switch, comparable to the optimization level. Editions should not be compared with language versions (e.g. C++17 and C++20).

Current editions
Currently there are three Rust editions:


 * Rust 2015, named after the release year of Rust 1.0, is the default edition, which is used if no edition is specified.
 * Rust 2018 is available since Rust version 1.31. All versions since then support both edition 2015 and 2018. This means that crates using the 2018 edition can depend on crates using the 2015 edition and vice versa.
 * Rust 2021 is available since Rust version 1.56. All versions since then support edition 2015, 2018 and 2021, so crates using these versions can be freely mixed.

Specifying the edition
When using cargo, the edition is specified in the  file with the   key: When invoking   manually, the   option should be used:

Timeline of the 2018 edition
Developing and releasing the 2018 edition involved a lot of planning and work from many parts of the Rust community. Here's a summary of the events:


 * In June 2017, proposing the concept of editions was published.
 * In September 2017, the RFC was accepted.
 * In March 2018, the plans to make a 2018 edition were announced for the first time on the Rust blog in the 2018 roadmap.
 * In September, Rust 1.29 was released, which shipped the  command to automatically migrate a project to the 2018 edition.
 * In October, Rust 1.30 was released, which shipped raw identifiers, so newly introduced keywords can be escaped.
 * In November, the redesigned website went online.
 * In December 2018, Rust 1.31, containing the 2018 edition, was released.

What changed with Rust 2018
This is a summary. More information can be found in the edition guide and in the Rust 2018 announcement.

Changes specific to the 2018 edition
The following features were released in Rust 1.31, unless a different version is indicated, and are (or were initially) only available in the 2018 edition:


 * The  and   keywords were reserved
 * the  keyword was reserved and   became a strict keyword.
 * Module paths were reworked, to make them simpler and more intuitive.
 * Anonymous trait parameters were deprecated.
 * Non-lexical lifetimes were introduced to make borrow checking more correct, permissive and provide better error messages.
 * They were backported to the 2015 edition in Rust 1.36.
 * The  operator   (matching at most one item) was added in Rust 1.32
 * It was backported to to the 2015 edition in Rust 1.37.
 * / was stabilized in Rust 1.39.

Other changes associated with Rust 2018
These changes are available in the 2015 edition as well, but were advertised together with the above features, because they were released around the same time:

Language changes

 * Improved lifetime elision
 * Raw identifiers
 * Attribute- and function-like procedural macros
 * applications
 * applications

Tools

 * , Rusts code formatter
 * , Rusts linter

Governance

 * A new edition of the book "The Rust Programming Language" was released
 * The website was redesigned
 * The Domain Working Groups for Network Services, Command-line applications, WebAssembly and Embedded devices were announced

What changed with Rust 2021
Unlike the 2018 edition, the 2021 edition was more limited in scope, and the Rust teams decided to not use the edition as a "rallying point" or to advertise new, unrelated features as part of the 2021 edition.

More information is available in the edition guide, in the Rust 2021 announcement and in the Rust 1.56 release announcement.


 * Additions to the prelude:, and  were added to the default prelude
 * Default cargo feature resolver: Cargo uses the new feature resolver by default for Rust 2021 crates.
 * for arrays:
 * Arrays implement  in all editions.
 * Calls to are hidden in Rust 2015 and Rust 2018 when using method call syntax (i.e., ). So,  still resolves to  as it has before.
 * changes meaning to be the call to  in Rust 2021.
 * Disjoint closure captures:
 * Closures only capture the needed struct fields, not the whole struct, when possible.
 * For example, only captures   and not.
 * Panic macro:
 * now always uses, just like.
 * This means that the first argument must be a string literal. To panic with other values, must be used.
 * The syntax, , and is now reserved.
 * Warnings promoted to errors: Trait objects without  and   range patterns are no longer allowed.
 * Or-patterns in :
 * The  metavariables can now match or-patterns (multiple patterns separated by  ).
 * For the previous behavior,  can be used.