Editions

From Rust Community Wiki
Jump to navigation Jump to search

The concept of editions was introduced in 2018 to allow stability without stagnation[1]. 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[edit | edit source]

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, dyn 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[edit | edit source]

Currently there are two 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 editions. This means that crates using the 2018 edition can depend on crates using the 2015 edition and vice versa.

Specifying the edition[edit | edit source]

When using cargo, the edition is specified in the Cargo.toml file with the edition key:

edition = "2018"

When invoking rustc manually, the --edition option should be used:

$ rustc src/main.rs --edition 2018

Timeline of the 2018 edition[edit | edit source]

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, RFC 2052: epochs proposing the concept of editions was published.
  • In September 2017, the RFC was accepted.[2]
  • In March 2018, the plans to make a 2018 edition were announced for the first time on the Rust blog in the 2018 roadmap.[3]
  • In September, Rust 1.29 was released, which shipped the cargo fix command to automatically migrate a project to the 2018 edition.[4]
  • In October, Rust 1.30 was released, which shipped raw identifiers, so newly introduced keywords can be escaped.[5]
  • In November, the redesigned website went online.[6]
  • In December 2018, Rust 1.31, containing the 2018 edition, was released.[7]

What changed with Rust 2018[edit | edit source]

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[edit | edit source]

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 async and await keywords were reserved
  • the try keyword was reserved and dyn 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 macro_rules! operator ? (matching at most one item) was added in Rust 1.32
    • It was backported to to the 2015 edition in Rust 1.37.
  • async/await was stabilized in Rust 1.39.

Other changes associated with Rust 2018[edit | edit source]

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[edit | edit source]

  • Improved lifetime elision
  • const fn
  • Raw identifiers
  • Attribute- and function-like procedural macros
  • no_std applications

Tools[edit | edit source]

  • rustfmt, Rusts code formatter
  • clippy, Rusts linter

Governance[edit | edit source]

  • 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

Future editions[edit | edit source]

Currently there are some ideas what features should be added in the next edition, but there are no concrete plans yet.

The next edition is often referred to as "Rust 2021", although it is unclear if the next edition will be released in 2021.

References[edit | edit source]