Protecting the Rust standard library from accidental breakage
The Rust standard library utilizes cargo-semver-checks to safeguard against unintentional alterations that could disrupt stable code. This initiative arose from several instances where modifications to the library led to incompatibilities with nightly Rust builds. In 2020, adding an unstable required method to a stable trait caused issues for the async-std library.
A generic method added to BuildHasher in 2021 lacked a where Self: Sized guard, rendering it nondynamic-safe. In 2022, a soundness fix for iterators like ChunksMut introduced instability, necessitating further adjustments to prevent conflicts with stable Rust. Most recently, in 2026, tokio developers discovered that their test suite failed to compile in Rust 1.94 on Windows due to the addition of unstable methods to a standard trait.
These incidents highlight the complexity of detecting accidental breakages, as even experienced developers and reviewers may overlook such issues. To address this, the Rust team developed cargo-semver-checks, which can now identify a range of problems, including the destabilization of previously stable APIs and the divergence between an item's name and its capabilities.
The tool works by extracting stability information from rustdoc JSON, enabling it to flag potential issues during the CI process. By employing this tool, the Rust standard library aims to maintain a consistent and reliable API across all releases, ensuring that developers can rely on the stability of the library without worrying about unexpected changes.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.