Skip to content

Commit 2185c8c

Browse files
committed
Rust 1.59.0
1 parent 457467b commit 2185c8c

File tree

1 file changed

+242
-0
lines changed

1 file changed

+242
-0
lines changed

posts/2022-02-24-Rust-1.59.0.md

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
---
2+
layout: post
3+
title: "Announcing Rust 1.59.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.59.0.
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, getting Rust 1.59.0 is as easy as:
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.59.0][notes] on GitHub.
20+
21+
[install]: https://www.rust-lang.org/install.html
22+
[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1590-2022-02-24
23+
24+
## What's in 1.59.0 stable
25+
26+
### Inline assembly
27+
28+
The Rust language now supports inline assembly. This enables many applications
29+
of Rust that need very low-level control over their execution, or access to
30+
specialized machine instructions.
31+
32+
When compiling for x86 and x86-64 targets, for instance, you can now write:
33+
34+
```rust
35+
use std::arch::asm;
36+
37+
// Multiply x by 6 using shifts and adds
38+
let mut x: u64 = 4;
39+
unsafe {
40+
asm!(
41+
"mov {tmp}, {x}",
42+
"shl {tmp}, 1",
43+
"shl {x}, 2",
44+
"add {x}, {tmp}",
45+
x = inout(reg) x,
46+
tmp = out(reg) _,
47+
);
48+
}
49+
assert_eq!(x, 4 * 6);
50+
```
51+
52+
The format string syntax used to name registers in the `asm!` and `global_asm!`
53+
macros is the same used in Rust format strings, so it should feel quite familiar
54+
to Rust programmers.
55+
56+
The syntax and instructions available in the assembly code itself vary according
57+
to the target architecture. Today, the following architectures are supported:
58+
59+
* x86 and x86-64
60+
* ARM
61+
* AArch64
62+
* RISC-V
63+
64+
You can see more examples of inline assembly in [Rust By Example][asm-example],
65+
and find more detailed documentation in the [reference][asm-reference].
66+
67+
[asm-example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
68+
[asm-reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
69+
70+
### Destructuring assignments
71+
72+
You can now use tuple, slice, and struct patterns as the left hand side of an
73+
assignment.
74+
75+
```rust
76+
let (a, b, c, d, e);
77+
78+
(a, b) = (1, 2);
79+
[c, .., d, _] = [1, 2, 3, 4, 5];
80+
Struct { e, .. } = Struct { e: 5, f: 3 };
81+
82+
assert_eq!([1, 2, 1, 4, 5], [a, b, c, d, e]);
83+
```
84+
85+
This makes assignment more consistent with let bindings, which allow you to do
86+
the same thing. Note that assignments with operators such as `+=` are not
87+
allowed.
88+
89+
### Const generics defaults and interleaving
90+
91+
Generic types can now specify default values for their const generics. For
92+
example, you can now write the following:
93+
94+
```rust
95+
struct ArrayStorage<T, const N: usize = 2> {
96+
arr: [T; N],
97+
}
98+
99+
impl<T> ArrayStorage<T> {
100+
fn new(a: T, b: T) -> ArrayStorage<T> {
101+
ArrayStorage {
102+
arr: [a, b],
103+
}
104+
}
105+
}
106+
```
107+
108+
Previously, type parameters were required to come before all const parameters.
109+
That restriction has been relaxed and you can now interleave them.
110+
111+
```rust
112+
fn cartesian_product<
113+
T, const N: usize,
114+
U, const M: usize,
115+
V, F
116+
>(a: [T; N], b: [U; M]) -> [[V; N]; M]
117+
where
118+
F: FnMut(&T, &U) -> V
119+
{
120+
// ...
121+
}
122+
```
123+
124+
### Future incompatibility warnings
125+
126+
Sometimes bugs in the Rust compiler cause it to accept code that should not
127+
have been accepted. An example of this was [borrows of packed struct
128+
fields][packed_borrows] being allowed in safe code.
129+
130+
[packed_borrows]: https://github.com/rust-lang/rust/issues/46043
131+
132+
While this happens very rarely, it can be quite disruptive when a crate used by
133+
your project has code that will no longer be allowed. In fact, you might not
134+
notice until your project inexplicably stops building!
135+
136+
cargo now shows you warnings when a dependency will be rejected by a future
137+
version of Rust. After running `cargo build` or `cargo check`, you might see:
138+
139+
```
140+
warning: the following packages contain code that will be rejected by a future version of Rust: old_dep v0.1.0
141+
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 1`
142+
```
143+
144+
You can run the `cargo report` command mentioned in the warning to see a full
145+
report of the code that will be rejected. This gives you time to upgrade your
146+
dependency before it breaks your build.
147+
148+
### Creating stripped binaries
149+
150+
It's often useful to strip unnecessary information like debuginfo from binaries
151+
you distribute, making them smaller.
152+
153+
While it has always been possible to do this manually after the binary is
154+
created, cargo and rustc now support stripping when the binary is linked. To
155+
enable this, add the following to your `Cargo.toml`:
156+
157+
```toml
158+
[profile.release]
159+
strip = "debuginfo"
160+
```
161+
162+
This causes debuginfo to be stripped from release binaries. You can also supply
163+
`"symbols"` or just `true` to strip all symbol information where supported.
164+
165+
### Stabilized APIs
166+
167+
The following methods and trait implementations were stabilized.
168+
169+
- [`std::thread::available_parallelism`][available_parallelism]
170+
- [`hash_map::Entry::insert_entry`][entry_insert_entry]
171+
- [`hash_map::VacantEntry::insert_entry`][vacant_insert_entry]
172+
- [`Result::copied`][result-copied]
173+
- [`Result::cloned`][result-cloned]
174+
- [`arch::asm!`][asm]
175+
- [`arch::global_asm!`][global_asm]
176+
- [`ops::ControlFlow::is_break`][is_break]
177+
- [`ops::ControlFlow::is_continue`][is_continue]
178+
- [`TryFrom<char> for u8`][try_from_char_u8]
179+
- [`char::TryFromCharError`][try_from_char_err]
180+
implementing `Clone`, `Debug`, `Display`, `PartialEq`, `Copy`, `Eq`, `Error`
181+
- [`iter::zip`][zip]
182+
- [`NonZeroU8::is_power_of_two`][is_power_of_two8]
183+
- [`NonZeroU16::is_power_of_two`][is_power_of_two16]
184+
- [`NonZeroU32::is_power_of_two`][is_power_of_two32]
185+
- [`NonZeroU64::is_power_of_two`][is_power_of_two64]
186+
- [`NonZeroU128::is_power_of_two`][is_power_of_two128]
187+
- [`DoubleEndedIterator for ToLowercase`][lowercase]
188+
- [`DoubleEndedIterator for ToUppercase`][uppercase]
189+
- [`TryFrom<&mut [T]> for [T; N]`][tryfrom_ref_arr]
190+
- [`UnwindSafe for Once`][unwindsafe_once]
191+
- [`RefUnwindSafe for Once`][refunwindsafe_once]
192+
- [armv8 neon intrinsics for aarch64][stdarch/1266]
193+
194+
The following previously stable functions are now `const`.
195+
196+
- [`mem::MaybeUninit::as_ptr`][muninit_ptr]
197+
- [`mem::MaybeUninit::assume_init`][muninit_init]
198+
- [`mem::MaybeUninit::assume_init_ref`][muninit_init_ref]
199+
- [`ffi::CStr::from_bytes_with_nul_unchecked`][cstr_from_bytes]
200+
201+
### Other changes
202+
203+
There are other changes in the Rust 1.59.0 release: check out what changed in
204+
[Rust](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1590-2022-02-24),
205+
[Cargo](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-159-2022-02-24),
206+
and [Clippy](https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-159).
207+
208+
### Contributors to 1.59.0
209+
210+
Many people came together to create Rust 1.59.0.
211+
We couldn't have done it without all of you.
212+
[Thanks!](https://thanks.rust-lang.org/rust/1.59.0/)
213+
214+
[cstr_from_bytes]: https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.from_bytes_with_nul_unchecked
215+
[muninit_ptr]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.as_ptr
216+
[muninit_init]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.assume_init
217+
[muninit_init_ref]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.assume_init_ref
218+
[unwindsafe_once]: https://doc.rust-lang.org/stable/std/sync/struct.Once.html#impl-UnwindSafe
219+
[refunwindsafe_once]: https://doc.rust-lang.org/stable/std/sync/struct.Once.html#impl-RefUnwindSafe
220+
[tryfrom_ref_arr]: https://doc.rust-lang.org/stable/std/convert/trait.TryFrom.html#impl-TryFrom%3C%26%27_%20mut%20%5BT%5D%3E
221+
[lowercase]: https://doc.rust-lang.org/stable/std/char/struct.ToLowercase.html#impl-DoubleEndedIterator
222+
[uppercase]: https://doc.rust-lang.org/stable/std/char/struct.ToUppercase.html#impl-DoubleEndedIterator
223+
[try_from_char_err]: https://doc.rust-lang.org/stable/std/char/struct.TryFromCharError.html
224+
[available_parallelism]: https://doc.rust-lang.org/stable/std/thread/fn.available_parallelism.html
225+
[entry_insert_entry]: https://doc.rust-lang.org/stable/std/collections/hash_map/enum.Entry.html#method.insert_entry
226+
[vacant_insert_entry]: https://doc.rust-lang.org/stable/std/collections/hash_map/struct.VacantEntry.html#method.insert_entry
227+
[result-copied]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.copied
228+
[result-cloned]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.cloned
229+
[option-copied]: https://doc.rust-lang.org/stable/std/result/enum.Option.html#method.copied
230+
[option-cloned]: https://doc.rust-lang.org/stable/std/result/enum.Option.html#method.cloned
231+
[asm]: https://doc.rust-lang.org/stable/core/arch/macro.asm.html
232+
[global_asm]: https://doc.rust-lang.org/stable/core/arch/macro.global_asm.html
233+
[is_break]: https://doc.rust-lang.org/stable/std/ops/enum.ControlFlow.html#method.is_break
234+
[is_continue]: https://doc.rust-lang.org/stable/std/ops/enum.ControlFlow.html#method.is_continue
235+
[try_from_char_u8]: https://doc.rust-lang.org/stable/std/primitive.char.html#impl-TryFrom%3Cchar%3E
236+
[zip]: https://doc.rust-lang.org/stable/std/iter/fn.zip.html
237+
[is_power_of_two8]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU8.html#method.is_power_of_two
238+
[is_power_of_two16]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU16.html#method.is_power_of_two
239+
[is_power_of_two32]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU32.html#method.is_power_of_two
240+
[is_power_of_two64]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU64.html#method.is_power_of_two
241+
[is_power_of_two128]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU128.html#method.is_power_of_two
242+
[stdarch/1266]: https://github.com/rust-lang/stdarch/pull/1266

0 commit comments

Comments
 (0)