Skip to content

Commit 545a9c7

Browse files
committed
Blog post for Rust 1.61.0
1 parent 01e5385 commit 545a9c7

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

posts/2022-05-19-Rust-1.61.0.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
layout: post
3+
title: "Announcing Rust 1.61.0"
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.61.0. Rust is a programming language
9+
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.61.0 with:
12+
13+
```console
14+
rustup update stable
15+
```
16+
17+
If you don't have it already, you can [get `rustup`][install]
18+
from the appropriate page on our website, and check out the
19+
[detailed release notes for 1.61.0][notes] on GitHub.
20+
21+
If you'd like to help us out by testing future releases, you might consider updating locally to use
22+
the beta channel (`rustup default beta`) or the nightly channel (`rustup default nightly`).
23+
Please [report] any bugs you might come across!
24+
25+
[install]: https://www.rust-lang.org/install.html
26+
[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1610-2022-05-19
27+
[report]: https://github.com/rust-lang/rust/issues/new/choose
28+
29+
## What's in 1.61.0 stable
30+
31+
### Custom exit codes from `main`
32+
33+
In the beginning, Rust `main` functions could only return the unit `()`, always indicating success
34+
in the exit status, and if you wanted otherwise you had to call `process::exit(code)`. Since Rust
35+
1.26, `main` has been allowed to return a `Result`, where `Ok` translated to a C `EXIT_SUCCESS` and
36+
`Err` to `EXIT_FAILURE` (also debug-printing the error). Under the hood, these alternate return
37+
types were unified by an unstable `Termination` trait.
38+
39+
In this release, that `Termination` trait is finally stable, along with a more general `ExitCode`
40+
type that wraps platform-specific return types. That has `SUCCESS` and `FAILURE` constants, and also
41+
implements `From<u8>` for more arbitrary values. The `Termination` trait can also be implemented for
42+
your own types, allowing you to customize any kind of reporting before converting to an `ExitCode`.
43+
44+
### More capabilities for `const fn`
45+
46+
Several incremental features have been stabilized in this release to enable more functionality in
47+
`const` functions:
48+
49+
* **Basic handling of `fn` pointers**: You can now create, pass, and cast function pointers in a
50+
`const fn`. For example, this could be useful to build compile-time function tables for an
51+
interpreter. However, it is still not permitted to call `fn` pointers.
52+
53+
* **Trait bounds**: You can now write trait bounds on generic parameters to `const fn`, such as
54+
`T: Copy`, where previously only `Sized` was allowed.
55+
56+
* **`dyn Trait` types**: Similarly, `const fn` can now deal with trait objects, `dyn Trait`.
57+
58+
* **`impl Trait` types**: Arguments and return values for `const fn` can now be opaque `impl Trait`
59+
types.
60+
61+
Note that the trait features do not yet support calling methods from those traits in a `const fn`.
62+
63+
See the [Constant Evaluation](https://doc.rust-lang.org/stable/reference/const_eval.html) section of
64+
the reference book to learn more about the current capabilities of `const` contexts, and future
65+
capabilities can be tracked in [rust#57563](https://github.com/rust-lang/rust/issues/57563).
66+
67+
### Static handles for locked stdio
68+
69+
The three standard I/O streams -- `Stdin`, `Stdout`, and `Stderr` -- each have a `lock(&self)` to
70+
allow more control over synchronizing read and writes. However, they returned lock guards with a
71+
lifetime borrowed from `&self`, so they were limited to the scope of the original handle. This was
72+
determined to be an unnecessary limitation, since the underlying locks were actually in static
73+
storage, so now the guards are returned with a `'static` lifetime, disconnected from the handle.
74+
75+
For example, a common error came from trying to get a handle and lock it in one statement:
76+
77+
```rust
78+
// error[E0716]: temporary value dropped while borrowed
79+
let out = std::io::stdout().lock();
80+
// ^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
81+
// |
82+
// creates a temporary which is freed while still in use
83+
```
84+
85+
Now the lock guard is `'static`, not borrowing from that temporary, so this works!
86+
87+
### Stabilized APIs
88+
89+
The following methods and trait implementations are now stabilized:
90+
91+
- [`Pin::static_mut`](https://doc.rust-lang.org/1.61.0/std/pin/struct.Pin.html#method.static_mut)
92+
- [`Pin::static_ref`](https://doc.rust-lang.org/1.61.0/std/pin/struct.Pin.html#method.static_ref)
93+
- [`Vec::retain_mut`](https://doc.rust-lang.org/1.61.0/std/vec/struct.Vec.html#method.retain_mut)
94+
- [`VecDeque::retain_mut`](https://doc.rust-lang.org/1.61.0/std/collections/struct.VecDeque.html#method.retain_mut)
95+
- [`Write` for `Cursor<[u8; N]>`](https://doc.rust-lang.org/1.61.0/std/io/struct.Cursor.html#impl-Write-4)
96+
- [`std::os::unix::net::SocketAddr::from_pathname`](https://doc.rust-lang.org/1.61.0/std/os/unix/net/struct.SocketAddr.html#method.from_pathname)
97+
- [`std::process::ExitCode`](https://doc.rust-lang.org/1.61.0/std/process/struct.ExitCode.html)
98+
- [`std::process::Termination`](https://doc.rust-lang.org/1.61.0/std/process/trait.Termination.html)
99+
- [`std::thread::JoinHandle::is_finished`](https://doc.rust-lang.org/1.61.0/std/thread/struct.JoinHandle.html#method.is_finished)
100+
101+
The following previously stable functions are now `const`:
102+
103+
- [`<*const T>::offset`](https://doc.rust-lang.org/1.61.0/std/primitive.pointer.html#method.offset)
104+
and [`<*mut T>::offset`](https://doc.rust-lang.org/1.61.0/std/primitive.pointer.html#method.offset-1)
105+
- [`<*const T>::wrapping_offset`](https://doc.rust-lang.org/1.61.0/std/primitive.pointer.html#method.wrapping_offset)
106+
and [`<*mut T>::wrapping_offset`](https://doc.rust-lang.org/1.61.0/std/primitive.pointer.html#method.wrapping_offset-1)
107+
- [`<*const T>::add`](https://doc.rust-lang.org/1.61.0/std/primitive.pointer.html#method.add)
108+
and [`<*mut T>::add`](https://doc.rust-lang.org/1.61.0/std/primitive.pointer.html#method.add-1)
109+
- [`<*const T>::sub`](https://doc.rust-lang.org/1.61.0/std/primitive.pointer.html#method.sub)
110+
and [`<*mut T>::sub`](https://doc.rust-lang.org/1.61.0/std/primitive.pointer.html#method.sub-1)
111+
- [`<*const T>::wrapping_add`](https://doc.rust-lang.org/1.61.0/std/primitive.pointer.html#method.wrapping_add)
112+
and [`<*mut T>::wrapping_add`](https://doc.rust-lang.org/1.61.0/std/primitive.pointer.html#method.wrapping_add-1)
113+
- [`<*const T>::wrapping_sub`](https://doc.rust-lang.org/1.61.0/std/primitive.pointer.html#method.wrapping_sub)
114+
and [`<*mut T>::wrapping_sub`](https://doc.rust-lang.org/1.61.0/std/primitive.pointer.html#method.wrapping_sub-1)
115+
- [`<[T]>::as_mut_ptr`](https://doc.rust-lang.org/1.61.0/std/primitive.slice.html#method.as_mut_ptr)
116+
- [`<[T]>::as_ptr_range`](https://doc.rust-lang.org/1.61.0/std/primitive.slice.html#method.as_ptr_range)
117+
- [`<[T]>::as_mut_ptr_range`](https://doc.rust-lang.org/1.61.0/std/primitive.slice.html#method.as_mut_ptr_range)
118+
119+
### Other changes
120+
121+
There are other changes in the Rust 1.61.0 release. Check out what changed in
122+
[Rust](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1610-2022-05-19),
123+
[Cargo](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-161-2022-05-19),
124+
and [Clippy](https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-161).
125+
126+
### Contributors to 1.61.0
127+
128+
Many people came together to create Rust 1.61.0.
129+
We couldn't have done it without all of you.
130+
[Thanks!](https://thanks.rust-lang.org/rust/1.61.0/)

0 commit comments

Comments
 (0)