FAQ - Help and questions

How stable is Rust? Will my code still compile next year?

#basics#cargo#why-rustpublished 0 replies0 views
ReplyWatch
Share
Hacker NewsRedditLinkedInE-mail

Short answer

Stable Rust promises that code which compiles on one stable release keeps compiling on later ones, with narrow exceptions such as fixing a soundness bug. Breaking changes are made only in editions, which each crate opts into with the edition key in Cargo.toml, and crates of different editions work together.

Checked with rustc 1.93.0, cargo 1.93.0

Frequently asked question, written and answered by the Ruststudio team. Replies are open: corrections are welcome.

#1

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.

Cargo.tomltoml
[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#

  1. Update the toolchain.
sh
   rustup update
  1. Build as before. A program that compiled with the previous version should still compile; new warnings may appear.
  1. To move a crate to a newer edition, run cargo fix --edition, which applies the automatic changes, then change the edition line 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 nightly feature in a project you need to keep building. Nightly can change at any time.

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#

    QuoteReply
    Share
    Hacker NewsRedditLinkedInE-mail

    No replies yet