|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.85.0 and Rust 2024" |
| 4 | +author: The Rust Release Team |
| 5 | +release: true |
| 6 | +--- |
| 7 | + |
| 8 | +The Rust team is happy to announce a new version of Rust, 1.85.0. This stabilizes the 2024 edition as well. |
| 9 | +Rust is a programming language empowering everyone to build reliable and efficient software. |
| 10 | + |
| 11 | +If you have a previous version of Rust installed via `rustup`, you can get 1.85.0 with: |
| 12 | + |
| 13 | +```console |
| 14 | +$ rustup update stable |
| 15 | +``` |
| 16 | + |
| 17 | +If you don't have it already, you can [get `rustup`](https://www.rust-lang.org/install.html) from the appropriate page on our website, and check out the [detailed release notes for 1.85.0](https://doc.rust-lang.org/stable/releases.html#version-1850-2025-02-20). |
| 18 | + |
| 19 | +If you'd like to help us out by testing future releases, you might consider updating locally to use the beta channel (`rustup default beta`) or the nightly channel (`rustup default nightly`). Please [report](https://github.com/rust-lang/rust/issues/new/choose) any bugs you might come across! |
| 20 | + |
| 21 | +## What's in 1.85.0 stable |
| 22 | + |
| 23 | +### Rust 2024 |
| 24 | + |
| 25 | +We are excited to announce that the Rust 2024 Edition is now stable! |
| 26 | +Editions are a mechanism for opt-in changes that may otherwise pose a backwards compatibility risk. See [the edition guide](https://doc.rust-lang.org/edition-guide/editions/index.html) for details on how this is achieved, and detailed instructions on how to migrate. |
| 27 | + |
| 28 | +This is the largest edition we have released. The [edition guide](https://doc.rust-lang.org/edition-guide/rust-2024/index.html) contains detailed information about each change, but as a summary, here are all the changes: |
| 29 | + |
| 30 | +- Language |
| 31 | + - [RPIT lifetime capture rules](https://doc.rust-lang.org/edition-guide/rust-2024/rpit-lifetime-capture.html) — Changes the default impl trait `use<..>` capturing. |
| 32 | + - [`if let` temporary scope](https://doc.rust-lang.org/edition-guide/rust-2024/temporary-if-let-scope.html) — Changes the scope of temporaries for `if let` expressions. |
| 33 | + - [Tail expression temporary scope](https://doc.rust-lang.org/edition-guide/rust-2024/temporary-tail-expr-scope.html) — Changes the scope of temporaries for the tail expression in a block. |
| 34 | + - [Match ergonomics reservations](https://doc.rust-lang.org/edition-guide/rust-2024/match-ergonomics.html) — New restrictions on pattern binding modes. |
| 35 | + - [Unsafe `extern` blocks](https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-extern.html) — `extern` blocks now require the `unsafe` keyword. |
| 36 | + - [Unsafe attributes](https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-attributes.html) — The `export_name`, `link_section`, and `no_mangle` attributes must now be marked as `unsafe`. |
| 37 | + - [`unsafe_op_in_unsafe_fn` warning](https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html) — The [`unsafe_op_in_unsafe_fn`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unsafe-op-in-unsafe-fn) lint now warns by default, requiring explicit `unsafe {}` blocks in `unsafe` functions. |
| 38 | + - [Disallow references to `static mut`](https://doc.rust-lang.org/edition-guide/rust-2024/static-mut-references.html) — References to `static mut` items now generate a deny-by-default error. |
| 39 | + - [Never type fallback change](https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html) — Changes to how the never type `!` coerces, and changes the [`never_type_fallback_flowing_into_unsafe`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#never-type-fallback-flowing-into-unsafe) lint level to "deny". |
| 40 | + - [Macro fragment specifiers](https://doc.rust-lang.org/edition-guide/rust-2024/macro-fragment-specifiers.html) — The `expr` macro fragment specifier in `macro_rules!` macros now also matches `const` and `_` expressions. |
| 41 | + - [Missing macro fragment specifiers](https://doc.rust-lang.org/edition-guide/rust-2024/missing-macro-fragment-specifiers.html) — The [`missing_fragment_specifier`](https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#missing-fragment-specifier) lint is now a hard error, rejecting macro meta variables without a fragment specifier kind. |
| 42 | + - [`gen` keyword](https://doc.rust-lang.org/edition-guide/rust-2024/gen-keyword.html) — Reserves the `gen` keyword in anticipation of adding generator blocks in the future. |
| 43 | + - [Reserved syntax](https://doc.rust-lang.org/edition-guide/rust-2024/reserved-syntax.html) — Reserves `#"foo"#` style strings and `##` tokens in anticipation of changing how guarded string literals may change in the future. |
| 44 | +- Standard library |
| 45 | + - [Changes to the prelude](https://doc.rust-lang.org/edition-guide/rust-2024/prelude.html) — Adds `Future` and `IntoFuture` to the prelude. |
| 46 | + - [Add `IntoIterator` for `Box<[T]>`](https://doc.rust-lang.org/edition-guide/rust-2024/intoiterator-box-slice.html) — Changes how iterators work with boxed slices. |
| 47 | + - [Newly unsafe functions](https://doc.rust-lang.org/edition-guide/rust-2024/newly-unsafe-functions.html) — `std::env::set_var`, `std::env::remove_var`, and `std::os::unix::process::CommandExt::before_exec` are now unsafe functions. |
| 48 | +- Cargo |
| 49 | + - [Cargo: Rust-version aware resolver](https://doc.rust-lang.org/edition-guide/rust-2024/cargo-resolver.html) — Changes the default dependency resolver behavior to consider the `rust-version` field. |
| 50 | + - [Cargo: Table and key name consistency](https://doc.rust-lang.org/edition-guide/rust-2024/cargo-table-key-names.html) — Removes some outdated `Cargo.toml` keys. |
| 51 | + - [Cargo: Reject unused inherited default-features](https://doc.rust-lang.org/edition-guide/rust-2024/cargo-inherited-default-features.html) — Changes how `default-features = false` works with inherited workspace dependencies. |
| 52 | +- Rustdoc |
| 53 | + - [Rustdoc combined tests](https://doc.rust-lang.org/edition-guide/rust-2024/rustdoc-doctests.html) — Doctests are now combined into a single executable, significantly improving performance. |
| 54 | + - [Rustdoc nested `include!` change](https://doc.rust-lang.org/edition-guide/rust-2024/rustdoc-nested-includes.html) — Changes to the relative path behavior of nested `include!` files. |
| 55 | +- Rustfmt |
| 56 | + - [Rustfmt: Style edition](https://doc.rust-lang.org/edition-guide/rust-2024/rustfmt-style-edition.html) — Introduces the concept of "style editions", which allow you to independently control the formatting edition from the Rust edition. |
| 57 | + - [Rustfmt: Formatting fixes](https://doc.rust-lang.org/edition-guide/rust-2024/rustfmt-formatting-fixes.html) — A large number of fixes to formatting various situations. |
| 58 | + - [Rustfmt: Combine all delimited exprs as last argument](https://doc.rust-lang.org/edition-guide/rust-2024/rustfmt-overflow-delimited-expr.html) — Changes to multi-line expressions as the last argument. |
| 59 | + - [Rustfmt: Raw identifier sorting](https://doc.rust-lang.org/edition-guide/rust-2024/rustfmt-raw-identifier-sorting.html) — Changes to how `r#foo` identifiers are sorted. |
| 60 | + - [Rustfmt: Version sorting](https://doc.rust-lang.org/edition-guide/rust-2024/rustfmt-version-sorting.html) — Changes to how identifiers that contain integers are sorted. |
| 61 | + |
| 62 | +#### Migrating to 2024 |
| 63 | + |
| 64 | +The guide includes migration instructions for all new features, and in general |
| 65 | +[transitioning an existing project to a new edition](https://doc.rust-lang.org/edition-guide/editions/transitioning-an-existing-project-to-a-new-edition.html). |
| 66 | +In many cases `cargo fix` can automate the necessary changes. You may even find that no changes in your code are needed at all for 2024! |
| 67 | + |
| 68 | +*Many* people came together to create this edition. We'd like to thank them all for their hard work! |
| 69 | + |
| 70 | +### `async` closures |
| 71 | + |
| 72 | +**🚧 TODO 🚧** |
| 73 | + |
| 74 | +- [Stabilize async closures](https://github.com/rust-lang/rust/pull/132706) |
| 75 | + See [RFC 3668](https://rust-lang.github.io/rfcs/3668-async-closures.html) for more details. |
| 76 | + |
| 77 | +### Hiding trait implementations from diagnostics |
| 78 | + |
| 79 | +- [Stabilize `#[diagnostic::do_not_recommend]`](https://github.com/rust-lang/rust/pull/132056) |
| 80 | + |
| 81 | +The new `#[diagnostic::do_not_recommend]` attribute is a hint to the compiler to not show the annotated trait implementation as part of a diagnostic message. For library authors, this is a way to keep the compiler from making suggestions that may be unhelpful or misleading. For example: |
| 82 | + |
| 83 | +```rust |
| 84 | +pub trait Foo {} |
| 85 | +pub trait Bar {} |
| 86 | + |
| 87 | +impl<T: Foo> Bar for T {} |
| 88 | + |
| 89 | +struct MyType; |
| 90 | + |
| 91 | +fn main() { |
| 92 | + let _object: &dyn Bar = &MyType; |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +```text |
| 97 | +error[E0277]: the trait bound `MyType: Bar` is not satisfied |
| 98 | + --> src/main.rs:9:29 |
| 99 | + | |
| 100 | +9 | let _object: &dyn Bar = &MyType; |
| 101 | + | ^^^^ the trait `Foo` is not implemented for `MyType` |
| 102 | + | |
| 103 | +note: required for `MyType` to implement `Bar` |
| 104 | + --> src/main.rs:4:14 |
| 105 | + | |
| 106 | +4 | impl<T: Foo> Bar for T {} |
| 107 | + | --- ^^^ ^ |
| 108 | + | | |
| 109 | + | unsatisfied trait bound introduced here |
| 110 | + = note: required for the cast from `&MyType` to `&dyn Bar` |
| 111 | +``` |
| 112 | + |
| 113 | +For some APIs, it might make good sense for you to implement `Foo`, and get `Bar` indirectly by that blanket implementation. For others, it might be expected that most users should implement `Bar` directly, so that `Foo` suggestion is a red herring. In that case, adding the diagnostic hint will change the error message like so: |
| 114 | + |
| 115 | +```rust |
| 116 | +#[diagnostic::do_not_recommend] |
| 117 | +impl<T: Foo> Bar for T {} |
| 118 | +``` |
| 119 | + |
| 120 | +```text |
| 121 | +error[E0277]: the trait bound `MyType: Bar` is not satisfied |
| 122 | + --> src/main.rs:10:29 |
| 123 | + | |
| 124 | +10 | let _object: &dyn Bar = &MyType; |
| 125 | + | ^^^^ the trait `Bar` is not implemented for `MyType` |
| 126 | + | |
| 127 | + = note: required for the cast from `&MyType` to `&dyn Bar` |
| 128 | +``` |
| 129 | + |
| 130 | +See [RFC 2397](https://rust-lang.github.io/rfcs/2397-do-not-recommend.html) for the original motivation, and the current [reference](https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-diagnosticdo_not_recommend-attribute) for more details. |
| 131 | + |
| 132 | +### `FromIterator` and `Extend` for tuples |
| 133 | + |
| 134 | +Earlier versions of Rust implemented convenience traits for iterators of `(T, U)` tuple pairs to behave like `Iterator::unzip`, with `Extend` in 1.56 and `FromIterator` in 1.79. These have now been *extended* to more tuple lengths, from singleton `(T,)` through to 12 items long, `(T1, T2, .., T11, T12)`. For example, you can now use `collect()` to fanout into multiple collections at once: |
| 135 | + |
| 136 | +```rust |
| 137 | +use std::collections::{LinkedList, VecDeque}; |
| 138 | +fn main() { |
| 139 | + let (squares, cubes, tesseracts): (Vec<_>, VecDeque<_>, LinkedList<_>) = |
| 140 | + (0i32..10).map(|i| (i * i, i.pow(3), i.pow(4))).collect(); |
| 141 | + println!("{squares:?}"); |
| 142 | + println!("{cubes:?}"); |
| 143 | + println!("{tesseracts:?}"); |
| 144 | +} |
| 145 | +``` |
| 146 | + |
| 147 | +```text |
| 148 | +[0, 1, 4, 9, 16, 25, 36, 49, 64, 81] |
| 149 | +[0, 1, 8, 27, 64, 125, 216, 343, 512, 729] |
| 150 | +[0, 1, 16, 81, 256, 625, 1296, 2401, 4096, 6561] |
| 151 | +``` |
| 152 | + |
| 153 | +### Updates to `home_dir()` |
| 154 | + |
| 155 | +`std::env::home_dir()` has been deprecated for years, because it can give surprising results in some Windows configurations if the `HOME` environment variable is set (which is not the normal configuration on Windows). We had previously avoided changing its behavior, out of concern for compatibility with code depending on this non-standard configuration. Given how long this function has been deprecated, we're now updating its behavior as a bug fix, and a subsequent release will remove the deprecation for this function. |
| 156 | + |
| 157 | +### Stabilized APIs |
| 158 | + |
| 159 | +- [`BuildHasherDefault::new`](https://doc.rust-lang.org/stable/std/hash/struct.BuildHasherDefault.html#method.new) |
| 160 | +- [`ptr::fn_addr_eq`](https://doc.rust-lang.org/std/ptr/fn.fn_addr_eq.html) |
| 161 | +- [`io::ErrorKind::QuotaExceeded`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.QuotaExceeded) |
| 162 | +- [`io::ErrorKind::CrossesDevices`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.CrossesDevices) |
| 163 | +- [`{float}::midpoint`](https://doc.rust-lang.org/core/primitive.f32.html#method.midpoint) |
| 164 | +- [Unsigned `{integer}::midpoint`](https://doc.rust-lang.org/std/primitive.u64.html#method.midpoint) |
| 165 | +- [`NonZeroU*::midpoint`](https://doc.rust-lang.org/std/num/type.NonZeroU32.html#method.midpoint) |
| 166 | +- [impl `std::iter::Extend` for tuples with arity 1 through 12](https://doc.rust-lang.org/stable/std/iter/trait.Extend.html#impl-Extend%3C(A,)%3E-for-(EA,)) |
| 167 | +- [`FromIterator<(A, ...)>` for tuples with arity 1 through 12](https://doc.rust-lang.org/stable/std/iter/trait.FromIterator.html#impl-FromIterator%3C(EA,)%3E-for-(A,)) |
| 168 | +- [`std::task::Waker::noop`](https://doc.rust-lang.org/stable/std/task/struct.Waker.html#method.noop) |
| 169 | + |
| 170 | +These APIs are now stable in const contexts |
| 171 | + |
| 172 | +- [`mem::size_of_val`](https://doc.rust-lang.org/stable/std/mem/fn.size_of_val.html) |
| 173 | +- [`mem::align_of_val`](https://doc.rust-lang.org/stable/std/mem/fn.align_of_val.html) |
| 174 | +- [`Layout::for_value`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.for_value) |
| 175 | +- [`Layout::align_to`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.align_to) |
| 176 | +- [`Layout::pad_to_align`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.pad_to_align) |
| 177 | +- [`Layout::extend`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.extend) |
| 178 | +- [`Layout::array`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.array) |
| 179 | +- [`std::mem::swap`](https://doc.rust-lang.org/stable/std/mem/fn.swap.html) |
| 180 | +- [`std::ptr::swap`](https://doc.rust-lang.org/stable/std/ptr/fn.swap.html) |
| 181 | +- [`NonNull::new`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.new) |
| 182 | +- [`HashMap::with_hasher`](https://doc.rust-lang.org/stable/std/collections/struct.HashMap.html#method.with_hasher) |
| 183 | +- [`HashSet::with_hasher`](https://doc.rust-lang.org/stable/std/collections/struct.HashSet.html#method.with_hasher) |
| 184 | +- [`BuildHasherDefault::new`](https://doc.rust-lang.org/stable/std/hash/struct.BuildHasherDefault.html#method.new) |
| 185 | +- [`<float>::recip`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.recip) |
| 186 | +- [`<float>::to_degrees`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.to_degrees) |
| 187 | +- [`<float>::to_radians`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.to_radians) |
| 188 | +- [`<float>::max`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.max) |
| 189 | +- [`<float>::min`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.min) |
| 190 | +- [`<float>::clamp`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.clamp) |
| 191 | +- [`<float>::abs`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.abs) |
| 192 | +- [`<float>::signum`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.signum) |
| 193 | +- [`<float>::copysign`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.copysign) |
| 194 | +- [`MaybeUninit::write`](https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.write) |
| 195 | + |
| 196 | +### Other changes |
| 197 | + |
| 198 | +Check out everything that changed in [Rust](https://github.com/rust-lang/rust/releases/tag/1.85.0), [Cargo](https://doc.rust-lang.org/nightly/cargo/CHANGELOG.html#cargo-185-2025-02-20), and [Clippy](https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-185). |
| 199 | + |
| 200 | +## Contributors to 1.85.0 |
| 201 | + |
| 202 | +Many people came together to create Rust 1.85.0. We couldn't have done it without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.85.0/) |
0 commit comments