Answer#
Rust releases a new stable version on a fixed six-week cycle, and the project's compatibility promise is that code written for stable Rust keeps compiling with later stable versions. The exceptions are limited and documented: a fix for a soundness bug, a change to something the documentation never promised, and warnings that become more strict. Code that uses nightly features is not covered, because nightly is where unfinished work lives.
Changes that would break existing code are not made in normal releases. They are collected into editions, released roughly every three years (2015, 2018, 2021 and 2024 so far). A crate chooses its edition in Cargo.toml, and a crate on the 2015 edition still compiles and links with crates on the 2024 edition, so you can upgrade one crate at a time.
[package]
name = "hello"
version = "0.1.0"
edition = "2024"cargo new writes the newest edition for the compiler that you have. With cargo 1.93.0 that was edition = "2024".
How to do it#
- Update the toolchain.
rustup update- Build as before. A program that compiled with the previous version should still compile; new warnings may appear.
- To move a crate to a newer edition, run
cargo fix --edition, which applies the automatic changes, then change theeditionline and build and test again.
Common mistakes#
- Pinning an old compiler forever to avoid updates. Updates are designed to be safe, and old compilers do not get security fixes.
- Confusing editions with versions of the compiler. The compiler version is the program you run; the edition is a setting of your crate.
- Depending on a
nightlyfeature in a project you need to keep building. Nightly can change at any time.
Related questions#
Does the Rust standard library change between releases?#
New functions and types are added in minor releases; existing stable ones are kept. Each item in the documentation shows the version in which it became stable.
Do I have to upgrade my edition?#
No. An old edition keeps working. Upgrade when you want the language changes it brings.
Sources#
- The Rust Edition Guide: https://doc.rust-lang.org/edition-guide/
- The Cargo Book, "The edition field": https://doc.rust-lang.org/cargo/reference/manifest.html#the-edition-field