diff --git a/originals/announcements/2025-01-09-Rust-1.84.0.md b/originals/announcements/2025-01-09-Rust-1.84.0.md index e8da20e..faf1024 100644 --- a/originals/announcements/2025-01-09-Rust-1.84.0.md +++ b/originals/announcements/2025-01-09-Rust-1.84.0.md @@ -19,32 +19,55 @@ If you'd like to help us out by testing future releases, you might consider upda ## What's in 1.84.0 stable -### Cargo can use toolchain version for library version selection +### Cargo considers Rust versions for dependency version selection 1.84.0 stabilizes the minimum supported Rust version (MSRV) aware resolver, -which uses the declared [minimum supported Rust version](https://doc.rust-lang.org/cargo/reference/rust-version.html) from -dependencies, if available, to improve package version selection. Rust version -aware selection allows library authors to easily adopt newer Rust versions -while allowing consumers of the library to automatically use old versions -if they need compatibility with older toolchains. +which prefers dependency versions compatible with the project's declared +[MSRV](https://doc.rust-lang.org/cargo/reference/rust-version.html). +With MSRV-aware version selection, the toil is reduced for maintainers to +support older toolchains by not needing to manually select older versions for +each dependency. -Library authors should take the MSRV-aware resolver into account when deciding +You can opt-in to the MSRV-aware resolver via [`.cargo/config.toml`](https://doc.rust-lang.org/cargo/reference/config.html#resolverincompatible-rust-versions): + +```toml +[resolver] +incompatible-rust-versions = "fallback" +``` + +Then when adding a dependency: + +```console +$ cargo add clap + Updating crates.io index +warning: ignoring clap@4.5.23 (which requires rustc 1.74) to maintain demo's rust-version of 1.60 + Adding clap v4.0.32 to dependencies + Updating crates.io index + Locking 33 packages to latest Rust 1.60 compatible versions + Adding clap v4.0.32 (available: v4.5.23, requires Rust 1.74) +``` + +When [verifying the latest dependencies in CI](https://doc.rust-lang.org/cargo/guide/continuous-integration.html#verifying-latest-dependencies), you can override this: + +```console +$ CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS=allow cargo update + Updating crates.io index + Locking 12 packages to latest compatible versions + Updating clap v4.0.32 -> v4.5.23 +``` + +You can also opt-in by setting [`package.resolver = "3"`](https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions) in the Cargo.toml manifest file though that will require raising your MSRV to 1.84. The new resolver will be enabled by default for projects using the 2024 edition +(which will stabilize in 1.85). + +This gives library authors more flexibility when deciding their policy on adopting new Rust toolchain features. Previously, a library adopting features from a new Rust toolchain would force downstream users of that library who have an older Rust version to either upgrade their toolchain or manually select an old version of the library compatible with their toolchain (and avoid running `cargo update`). Now, those users will be able to automatically use older library versions compatible with their older toolchain. -In the future, we expect this to provide more flexibility for library authors -to select their preferred support strategy for Rust versions, with the toolchain -helping users on older toolchains avoid breakage. - -The new resolver will be enabled by default with the 2024 edition (expected to -stabilize in 1.85), but can be enabled as of 1.84 by setting -[`package.resolver = "3"`](https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions) in the Cargo.toml manifest file, or -[`resolver.incompatible-rust-versions = "fallback"`](https://doc.rust-lang.org/cargo/reference/config.html#resolverincompatible-rust-versions) in the Cargo configuration file. -Read [the documentation](https://doc.rust-lang.org/cargo/reference/resolver.html#rust-version) for more details. +See the [documentation](https://doc.rust-lang.org/cargo/reference/rust-version.html#setting-and-updating-rust-version) for more considerations when deciding on an MSRV policy. ### Migration to a new trait solver begins @@ -54,7 +77,7 @@ component of Rust's type system. It is not only responsible for checking whether trait-bounds - e.g. `Vec: Clone` - hold, but is also used by many other parts of the type system, such as normalization - figuring out the underlying type of ` as IntoIterator>::Item` - and equating types -(checking whether T and U are the same). +(checking whether `T` and `U` are the same). In 1.84, the new solver is used for checking coherence of trait impls. At a high level, coherence is responsible for ensuring that there is at most one @@ -70,23 +93,22 @@ engine used relatively esoteric code. It also improves our ability to detect where impls do *not* overlap, allowing more code to be written in some cases. For more details, see a [previous blog post](https://blog.rust-lang.org/inside-rust/2024/12/04/trait-system-refactor-initiative.html) -and the [stabilization report](https://github.com/rust-lang/rust/pull/130654) +and the [stabilization report](https://github.com/rust-lang/rust/pull/130654). [Crater]: https://github.com/rust-lang/crater/ ### Strict provenance APIs -In Rust, [pointers are not simply an “integer” or -“address”](https://rust-lang.github.io/rfcs/3559-rust-has-provenance.html). For -instance, it’s uncontroversial to say that a Use After Free is clearly -Undefined Behavior, even if you “get lucky” and the freed memory gets -reallocated before your read/write. It is also uncontroversial that writing -through a pointer derived from an `&i32` reference is Undefined Behavior, even +In Rust, [pointers are not simply an "integer" or +"address"](https://rust-lang.github.io/rfcs/3559-rust-has-provenance.html). For +instance, a "use after free" is undefined behavior even if you "get lucky" and the freed memory gets +reallocated before your read/write. As another example, writing +through a pointer derived from an `&i32` reference is undefined behavior, even if writing to the same address via a different pointer is legal. The underlying pattern here is that *the way a pointer is computed matters*, not just the address that results from this computation. For this reason, we say that -pointers have **provenance**: to fully characterize pointer-related Undefined -Behavior in Rust, we have to know not only the address the pointer points to, +pointers have **provenance**: to fully characterize pointer-related undefined +behavior in Rust, we have to know not only the address the pointer points to, but also track which other pointer(s) it is "derived from". Most of the time, programmers do not need to worry much about provenance, and @@ -106,7 +128,48 @@ For more details, see the standard library [documentation on provenance](https:/ ### Stabilized APIs -TODO, relnotes still in-progress for this section +- [`Ipv6Addr::is_unique_local`](https://doc.rust-lang.org/stable/core/net/struct.Ipv6Addr.html#method.is_unique_local) +- [`Ipv6Addr::is_unicast_link_local`](https://doc.rust-lang.org/stable/core/net/struct.Ipv6Addr.html#method.is_unicast_link_local) +- [`core::ptr::with_exposed_provenance`](https://doc.rust-lang.org/stable/core/ptr/fn.with_exposed_provenance.html) +- [`core::ptr::with_exposed_provenance_mut`](https://doc.rust-lang.org/stable/core/ptr/fn.with_exposed_provenance_mut.html) +- [`::addr`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.addr) +- [`::expose_provenance`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.expose_provenance) +- [`::with_addr`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.with_addr) +- [`::map_addr`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.map_addr) +- [`::isqrt`](https://doc.rust-lang.org/stable/core/primitive.i32.html#method.isqrt) +- [`::checked_isqrt`](https://doc.rust-lang.org/stable/core/primitive.i32.html#method.checked_isqrt) +- [`::isqrt`](https://doc.rust-lang.org/stable/core/primitive.u32.html#method.isqrt) +- [`NonZero::isqrt`](https://doc.rust-lang.org/stable/core/num/struct.NonZero.html#impl-NonZero%3Cu128%3E/method.isqrt) +- [`core::ptr::without_provenance`](https://doc.rust-lang.org/stable/core/ptr/fn.without_provenance.html) +- [`core::ptr::without_provenance_mut`](https://doc.rust-lang.org/stable/core/ptr/fn.without_provenance_mut.html) +- [`core::ptr::dangling`](https://doc.rust-lang.org/stable/core/ptr/fn.dangling.html) +- [`core::ptr::dangling_mut`](https://doc.rust-lang.org/stable/core/ptr/fn.dangling_mut.html) + +These APIs are now stable in const contexts + +- [`AtomicBool::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicBool.html#method.from_ptr) +- [`AtomicPtr::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicPtr.html#method.from_ptr) +- [`AtomicU8::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicU8.html#method.from_ptr) +- [`AtomicU16::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicU16.html#method.from_ptr) +- [`AtomicU32::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicU32.html#method.from_ptr) +- [`AtomicU64::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicU64.html#method.from_ptr) +- [`AtomicUsize::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicUsize.html#method.from_ptr) +- [`AtomicI8::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicI8.html#method.from_ptr) +- [`AtomicI16::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicI16.html#method.from_ptr) +- [`AtomicI32::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicI32.html#method.from_ptr) +- [`AtomicI64::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicI64.html#method.from_ptr) +- [`AtomicIsize::from_ptr`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicIsize.html#method.from_ptr) +- [`::is_null`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.is_null-1) +- [`::as_ref`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.as_ref-1) +- [`::as_mut`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.as_mut) +- [`Pin::new`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.new) +- [`Pin::new_unchecked`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.new_unchecked) +- [`Pin::get_ref`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.get_ref) +- [`Pin::into_ref`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.into_ref) +- [`Pin::get_mut`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.get_mut) +- [`Pin::get_unchecked_mut`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.get_unchecked_mut) +- [`Pin::static_ref`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.static_ref) +- [`Pin::static_mut`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.static_mut) ### Other changes