What Are Rust Editions and How Do They Affect Compilation?

Rust editions are versioned language snapshots defined in Cargo.toml that control syntax and features without breaking existing code.

Rust editions are versioned snapshots of the language that allow new features and syntax changes without breaking existing code. You specify the edition in your Cargo.toml file under the [package] section, which tells the compiler which set of rules and keywords to apply during compilation. If omitted, the compiler defaults to the 2015 edition for backward compatibility.

[package]
name = "my-project"
version = "0.1.0"
edition = "2021"

The available editions are 2015, 2018, 2021, and 2024. Changing the edition can enable new syntax (like async/await or raw identifiers) or change how the compiler resolves paths, but it does not require recompiling dependencies that use different editions.