What are Rust editions and what changed across 2015, 2018, and 2021?
Answer
Rust editions are a mechanism for introducing backwards-incompatible syntax and semantic changes without breaking existing code — crates opt into an edition in Cargo.toml with edition = "2021", and different edition crates interoperate seamlessly. Rust 2015 (the original stable release): no edition keyword needed, extern crate required to use external crates. Rust 2018: eliminated the extern crate declaration (crates in Cargo.toml are automatically in scope), introduced the async/await syntax, dyn Trait became required (previously bare Trait meant trait objects), improved module system (no more mod.rs required, path clarity improvements), non-lexical lifetimes (NLL) enabled by default for smarter borrow checking. Rust 2021: closure capture becomes more precise (closures capture individual fields not whole structs), IntoIterator for arrays, disjoint capture in closures reduces the need for explicit moves, and the panic!() macro formatting was standardized. A new edition is planned approximately every 3 years.
More Rust Questions
View all →- Advanced What are zero-cost abstractions and monomorphization in Rust?
- Advanced What are Pin<T> and Unpin in Rust async programming?
- Advanced How does the async runtime work internally in Rust (Waker, Poll, Executor)?
- Advanced What are the rules for writing correct unsafe Rust?
- Advanced How does Rust FFI (Foreign Function Interface) work with C?