Skip to content

Commit 6f509e9

Browse files
authored
Merge pull request #1481 from cuviper/rust-1.85.0
Announcing Rust 1.85.0 and Rust 2024
2 parents 58b217b + 56daa99 commit 6f509e9

File tree

1 file changed

+232
-0
lines changed

1 file changed

+232
-0
lines changed

posts/2025-02-20-Rust-1.85.0.md

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
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 capturing of parameters by `impl Trait` types when `use<..>` is not present.
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) — Disallow some pattern combinations to avoid confusion and allow for future improvements.
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 be parsed 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: 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.
59+
- [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.
60+
61+
#### Migrating to 2024
62+
63+
The guide includes migration instructions for all new features, and in general
64+
[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).
65+
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!
66+
67+
Note that automatic fixes via `cargo fix` are very conservative to avoid ever changing the semantics of your code. In many cases you may wish to keep your code the same and use the new semantics of Rust 2024; for instance, continuing to use the `expr` macro matcher, and ignoring the conversions of conditionals because you want the new 2024 drop order semantics. The result of `cargo fix` should not be considered a recommendation, just a conservative conversion that preserves behavior.
68+
69+
*Many* people came together to create this edition. We'd like to thank them all for their hard work!
70+
71+
### `async` closures
72+
73+
Rust now supports asynchronous closures like `async || {}` which return futures when called. This works like an `async fn` which can also capture values from the local environment, just like the difference between regular closures and functions. This also comes with 3 analogous traits in the standard library prelude: `AsyncFn`, `AsyncFnMut`, and `AsyncFnOnce`.
74+
75+
In some cases, you could already approximate this with a regular closure and an asynchronous block, like `|| async {}`. However, the future returned by such an inner block is not able to borrow from the closure captures, but this does work with `async` closures:
76+
77+
```rust
78+
let mut vec: Vec<String> = vec![];
79+
80+
let closure = async || {
81+
vec.push(ready(String::from("")).await);
82+
};
83+
```
84+
85+
It also has not been possible to properly express higher-ranked function signatures with the `Fn` traits returning a `Future`, but you can write this with the `AsyncFn` traits:
86+
87+
```rust
88+
use core::future::Future;
89+
async fn f<Fut>(_: impl for<'a> Fn(&'a u8) -> Fut)
90+
where
91+
Fut: Future<Output = ()>,
92+
{ todo!() }
93+
94+
async fn f2(_: impl for<'a> AsyncFn(&'a u8))
95+
{ todo!() }
96+
97+
async fn main() {
98+
async fn g(_: &u8) { todo!() }
99+
f(g).await;
100+
//~^ ERROR mismatched types
101+
//~| ERROR one type is more general than the other
102+
103+
f2(g).await; // ok!
104+
}
105+
```
106+
107+
So `async` closures provide first-class solutions to both of these problems! See [RFC 3668](https://rust-lang.github.io/rfcs/3668-async-closures.html) and the [stabilization report](https://github.com/rust-lang/rust/pull/132706) for more details.
108+
109+
### Hiding trait implementations from diagnostics
110+
111+
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:
112+
113+
```rust
114+
pub trait Foo {}
115+
pub trait Bar {}
116+
117+
impl<T: Foo> Bar for T {}
118+
119+
struct MyType;
120+
121+
fn main() {
122+
let _object: &dyn Bar = &MyType;
123+
}
124+
```
125+
126+
```text
127+
error[E0277]: the trait bound `MyType: Bar` is not satisfied
128+
--> src/main.rs:9:29
129+
|
130+
9 | let _object: &dyn Bar = &MyType;
131+
| ^^^^ the trait `Foo` is not implemented for `MyType`
132+
|
133+
note: required for `MyType` to implement `Bar`
134+
--> src/main.rs:4:14
135+
|
136+
4 | impl<T: Foo> Bar for T {}
137+
| --- ^^^ ^
138+
| |
139+
| unsatisfied trait bound introduced here
140+
= note: required for the cast from `&MyType` to `&dyn Bar`
141+
```
142+
143+
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:
144+
145+
```rust
146+
#[diagnostic::do_not_recommend]
147+
impl<T: Foo> Bar for T {}
148+
```
149+
150+
```text
151+
error[E0277]: the trait bound `MyType: Bar` is not satisfied
152+
--> src/main.rs:10:29
153+
|
154+
10 | let _object: &dyn Bar = &MyType;
155+
| ^^^^ the trait `Bar` is not implemented for `MyType`
156+
|
157+
= note: required for the cast from `&MyType` to `&dyn Bar`
158+
```
159+
160+
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.
161+
162+
### `FromIterator` and `Extend` for tuples
163+
164+
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:
165+
166+
```rust
167+
use std::collections::{LinkedList, VecDeque};
168+
fn main() {
169+
let (squares, cubes, tesseracts): (Vec<_>, VecDeque<_>, LinkedList<_>) =
170+
(0i32..10).map(|i| (i * i, i.pow(3), i.pow(4))).collect();
171+
println!("{squares:?}");
172+
println!("{cubes:?}");
173+
println!("{tesseracts:?}");
174+
}
175+
```
176+
177+
```text
178+
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
179+
[0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
180+
[0, 1, 16, 81, 256, 625, 1296, 2401, 4096, 6561]
181+
```
182+
183+
### Updates to `std::env::home_dir()`
184+
185+
`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.
186+
187+
### Stabilized APIs
188+
189+
- [`BuildHasherDefault::new`](https://doc.rust-lang.org/stable/std/hash/struct.BuildHasherDefault.html#method.new)
190+
- [`ptr::fn_addr_eq`](https://doc.rust-lang.org/std/ptr/fn.fn_addr_eq.html)
191+
- [`io::ErrorKind::QuotaExceeded`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.QuotaExceeded)
192+
- [`io::ErrorKind::CrossesDevices`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.CrossesDevices)
193+
- [`{float}::midpoint`](https://doc.rust-lang.org/core/primitive.f32.html#method.midpoint)
194+
- [Unsigned `{integer}::midpoint`](https://doc.rust-lang.org/std/primitive.u64.html#method.midpoint)
195+
- [`NonZeroU*::midpoint`](https://doc.rust-lang.org/std/num/type.NonZeroU32.html#method.midpoint)
196+
- [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,))
197+
- [`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,))
198+
- [`std::task::Waker::noop`](https://doc.rust-lang.org/stable/std/task/struct.Waker.html#method.noop)
199+
200+
These APIs are now stable in const contexts
201+
202+
- [`mem::size_of_val`](https://doc.rust-lang.org/stable/std/mem/fn.size_of_val.html)
203+
- [`mem::align_of_val`](https://doc.rust-lang.org/stable/std/mem/fn.align_of_val.html)
204+
- [`Layout::for_value`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.for_value)
205+
- [`Layout::align_to`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.align_to)
206+
- [`Layout::pad_to_align`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.pad_to_align)
207+
- [`Layout::extend`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.extend)
208+
- [`Layout::array`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.array)
209+
- [`std::mem::swap`](https://doc.rust-lang.org/stable/std/mem/fn.swap.html)
210+
- [`std::ptr::swap`](https://doc.rust-lang.org/stable/std/ptr/fn.swap.html)
211+
- [`NonNull::new`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.new)
212+
- [`HashMap::with_hasher`](https://doc.rust-lang.org/stable/std/collections/struct.HashMap.html#method.with_hasher)
213+
- [`HashSet::with_hasher`](https://doc.rust-lang.org/stable/std/collections/struct.HashSet.html#method.with_hasher)
214+
- [`BuildHasherDefault::new`](https://doc.rust-lang.org/stable/std/hash/struct.BuildHasherDefault.html#method.new)
215+
- [`<float>::recip`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.recip)
216+
- [`<float>::to_degrees`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.to_degrees)
217+
- [`<float>::to_radians`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.to_radians)
218+
- [`<float>::max`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.max)
219+
- [`<float>::min`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.min)
220+
- [`<float>::clamp`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.clamp)
221+
- [`<float>::abs`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.abs)
222+
- [`<float>::signum`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.signum)
223+
- [`<float>::copysign`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.copysign)
224+
- [`MaybeUninit::write`](https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.write)
225+
226+
### Other changes
227+
228+
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).
229+
230+
## Contributors to 1.85.0
231+
232+
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

Comments
 (0)