Skip to content

Commit 153b509

Browse files
tmandryMark-Simulacrum
authored andcommitted
Rust 1.59.0
1 parent 71e2096 commit 153b509

File tree

1 file changed

+282
-0
lines changed

1 file changed

+282
-0
lines changed

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

+282
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
---
2+
layout: post
3+
title: "Announcing Rust 1.59.0"
4+
author: The Rust Team
5+
release: true
6+
---
7+
8+
The Rust team has published a new version of Rust, 1.59.0. Rust is a programming
9+
language that is empowering everyone to build reliable and efficient software.
10+
11+
---
12+
13+
Today's release falls on the day in which the world's attention is captured by
14+
the sudden invasion of Ukraine by Putin's forces. Before going into the details
15+
of the new Rust release, we'd like to state that we stand in solidarity with the
16+
people of Ukraine and express our support for all people affected by this
17+
conflict.
18+
19+
----
20+
21+
If you have a previous version of Rust installed via rustup, you can get 1.59.0
22+
with:
23+
24+
```console
25+
rustup update stable
26+
```
27+
28+
If you don't have it already, you can [get `rustup`][install]
29+
from the appropriate page on our website, and check out the
30+
[detailed release notes for 1.59.0][notes] on GitHub.
31+
32+
[install]: https://www.rust-lang.org/install.html
33+
[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1590-2022-02-24
34+
35+
## What's in 1.59.0 stable
36+
37+
### Inline assembly
38+
39+
The Rust language now supports inline assembly. This enables many applications
40+
that need very low-level control over their execution, or access to
41+
specialized machine instructions.
42+
43+
When compiling for x86-64 targets, for instance, you can now write:
44+
45+
```rust
46+
use std::arch::asm;
47+
48+
// Multiply x by 6 using shifts and adds
49+
let mut x: u64 = 4;
50+
unsafe {
51+
asm!(
52+
"mov {tmp}, {x}",
53+
"shl {tmp}, 1",
54+
"shl {x}, 2",
55+
"add {x}, {tmp}",
56+
x = inout(reg) x,
57+
tmp = out(reg) _,
58+
);
59+
}
60+
assert_eq!(x, 4 * 6);
61+
```
62+
63+
The format string syntax used to name registers in the `asm!` and `global_asm!`
64+
macros is the same used in Rust [format strings], so it should feel quite familiar
65+
to Rust programmers.
66+
67+
The assembly language and instructions available with inline assembly vary
68+
according to the target architecture. Today, the stable Rust compiler supports
69+
inline assembly on the following architectures:
70+
71+
* x86 and x86-64
72+
* ARM
73+
* AArch64
74+
* RISC-V
75+
76+
You can see more examples of inline assembly in [Rust By Example][asm-example],
77+
and find more detailed documentation in the [reference][asm-reference].
78+
79+
[asm-example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
80+
[asm-reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
81+
[format strings]: https://doc.rust-lang.org/stable/std/fmt/
82+
83+
### Destructuring assignments
84+
85+
You can now use tuple, slice, and struct patterns as the left-hand side of an
86+
assignment.
87+
88+
```rust
89+
let (a, b, c, d, e);
90+
91+
(a, b) = (1, 2);
92+
[c, .., d, _] = [1, 2, 3, 4, 5];
93+
Struct { e, .. } = Struct { e: 5, f: 3 };
94+
95+
assert_eq!([1, 2, 1, 4, 5], [a, b, c, d, e]);
96+
```
97+
98+
This makes assignment more consistent with `let` bindings, which have long
99+
supported the same thing. Note that destructuring assignments with operators
100+
such as `+=` are not allowed.
101+
102+
### Const generics defaults and interleaving
103+
104+
Generic types can now specify default values for their const generics. For
105+
example, you can now write the following:
106+
107+
```rust
108+
struct ArrayStorage<T, const N: usize = 2> {
109+
arr: [T; N],
110+
}
111+
112+
impl<T> ArrayStorage<T> {
113+
fn new(a: T, b: T) -> ArrayStorage<T> {
114+
ArrayStorage {
115+
arr: [a, b],
116+
}
117+
}
118+
}
119+
```
120+
121+
Previously, type parameters were required to come before all const parameters.
122+
That restriction has been relaxed and you can now interleave them.
123+
124+
```rust
125+
fn cartesian_product<
126+
T, const N: usize,
127+
U, const M: usize,
128+
V, F
129+
>(a: [T; N], b: [U; M]) -> [[V; N]; M]
130+
where
131+
F: FnMut(&T, &U) -> V
132+
{
133+
// ...
134+
}
135+
```
136+
137+
### Future incompatibility warnings
138+
139+
Sometimes bugs in the Rust compiler cause it to accept code that should not
140+
have been accepted. An example of this was [borrows of packed struct
141+
fields][packed_borrows] being allowed in safe code.
142+
143+
[packed_borrows]: https://github.com/rust-lang/rust/issues/46043
144+
145+
While this happens very rarely, it can be quite disruptive when a crate used by
146+
your project has code that will no longer be allowed. In fact, you might not
147+
notice until your project inexplicably stops building!
148+
149+
Cargo now shows you warnings when a dependency will be rejected by a future
150+
version of Rust. After running `cargo build` or `cargo check`, you might see:
151+
152+
```
153+
warning: the following packages contain code that will be rejected by a future version of Rust: old_dep v0.1.0
154+
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 1`
155+
```
156+
157+
You can run the `cargo report` command mentioned in the warning to see a full
158+
report of the code that will be rejected. This gives you time to upgrade your
159+
dependency before it breaks your build.
160+
161+
### Creating stripped binaries
162+
163+
It's often useful to strip unnecessary information like debuginfo from binaries
164+
you distribute, making them smaller.
165+
166+
While it has always been possible to do this manually after the binary is
167+
created, cargo and rustc now support stripping when the binary is linked. To
168+
enable this, add the following to your `Cargo.toml`:
169+
170+
```toml
171+
[profile.release]
172+
strip = "debuginfo"
173+
```
174+
175+
This causes debuginfo to be stripped from release binaries. You can also supply
176+
`"symbols"` or just `true` to strip all symbol information where supported.
177+
178+
The standard library typically ships with debug symbols and line-level
179+
debuginfo, so Rust binaries built without debug symbols enabled still include
180+
the debug information from the standard library by default. Using the `strip`
181+
option allows you to remove this extra information, producing smaller Rust
182+
binaries.
183+
184+
See [Cargo's documentation][cargo-docs] for more details.
185+
186+
[cargo-docs]: https://doc.rust-lang.org/beta/cargo/reference/profiles.html#strip
187+
188+
### Incremental compilation off by default
189+
190+
The 1.59.0 release disables incremental by default (unless explicitly asked for
191+
by via an environment variable: `RUSTC_FORCE_INCREMENTAL=1`). This mitigates a
192+
the effects of a known bug, [#94124], which can cause deserialization errors (and panics) during compilation
193+
with incremental compilation turned on.
194+
195+
The specific fix for [#94124] has landed and is currently in the 1.60 beta,
196+
which will ship in six weeks. We are not presently aware of other issues that
197+
would encourage a decision to disable incremental in 1.60 stable, and if none
198+
arise it is likely that 1.60 stable will re-enable incremental compilation
199+
again. Incremental compilation remains on by default in the beta and nightly
200+
channels.
201+
202+
As always, we encourage users to test on the nightly and beta channels and
203+
report issues you find: particularly for incremental bugs, this is the best way
204+
to ensure the Rust team can judge whether there is breakage and the number of
205+
users it affects.
206+
207+
[#94124]: https://github.com/rust-lang/rust/issues/94124
208+
209+
### Stabilized APIs
210+
211+
The following methods and trait implementations are now stabilized:
212+
213+
- [`std::thread::available_parallelism`][available_parallelism]
214+
- [`Result::copied`][result-copied]
215+
- [`Result::cloned`][result-cloned]
216+
- [`arch::asm!`][asm]
217+
- [`arch::global_asm!`][global_asm]
218+
- [`ops::ControlFlow::is_break`][is_break]
219+
- [`ops::ControlFlow::is_continue`][is_continue]
220+
- [`TryFrom<char> for u8`][try_from_char_u8]
221+
- [`char::TryFromCharError`][try_from_char_err]
222+
implementing `Clone`, `Debug`, `Display`, `PartialEq`, `Copy`, `Eq`, `Error`
223+
- [`iter::zip`][zip]
224+
- [`NonZeroU8::is_power_of_two`][is_power_of_two8]
225+
- [`NonZeroU16::is_power_of_two`][is_power_of_two16]
226+
- [`NonZeroU32::is_power_of_two`][is_power_of_two32]
227+
- [`NonZeroU64::is_power_of_two`][is_power_of_two64]
228+
- [`NonZeroU128::is_power_of_two`][is_power_of_two128]
229+
- [`DoubleEndedIterator for ToLowercase`][lowercase]
230+
- [`DoubleEndedIterator for ToUppercase`][uppercase]
231+
- [`TryFrom<&mut [T]> for [T; N]`][tryfrom_ref_arr]
232+
- [`UnwindSafe for Once`][unwindsafe_once]
233+
- [`RefUnwindSafe for Once`][refunwindsafe_once]
234+
- [armv8 neon intrinsics for aarch64][stdarch/1266]
235+
236+
The following previously stable functions are now `const`:
237+
238+
- [`mem::MaybeUninit::as_ptr`][muninit_ptr]
239+
- [`mem::MaybeUninit::assume_init`][muninit_init]
240+
- [`mem::MaybeUninit::assume_init_ref`][muninit_init_ref]
241+
- [`ffi::CStr::from_bytes_with_nul_unchecked`][cstr_from_bytes]
242+
243+
### Other changes
244+
245+
There are other changes in the Rust 1.59.0 release. Check out what changed in
246+
[Rust](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1590-2022-02-24),
247+
[Cargo](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-159-2022-02-24),
248+
and [Clippy](https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-159).
249+
250+
### Contributors to 1.59.0
251+
252+
Many people came together to create Rust 1.59.0.
253+
We couldn't have done it without all of you.
254+
[Thanks!](https://thanks.rust-lang.org/rust/1.59.0/)
255+
256+
[cstr_from_bytes]: https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.from_bytes_with_nul_unchecked
257+
[muninit_ptr]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.as_ptr
258+
[muninit_init]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.assume_init
259+
[muninit_init_ref]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.assume_init_ref
260+
[unwindsafe_once]: https://doc.rust-lang.org/stable/std/sync/struct.Once.html#impl-UnwindSafe
261+
[refunwindsafe_once]: https://doc.rust-lang.org/stable/std/sync/struct.Once.html#impl-RefUnwindSafe
262+
[tryfrom_ref_arr]: https://doc.rust-lang.org/stable/std/convert/trait.TryFrom.html#impl-TryFrom%3C%26%27_%20mut%20%5BT%5D%3E
263+
[lowercase]: https://doc.rust-lang.org/stable/std/char/struct.ToLowercase.html#impl-DoubleEndedIterator
264+
[uppercase]: https://doc.rust-lang.org/stable/std/char/struct.ToUppercase.html#impl-DoubleEndedIterator
265+
[try_from_char_err]: https://doc.rust-lang.org/stable/std/char/struct.TryFromCharError.html
266+
[available_parallelism]: https://doc.rust-lang.org/stable/std/thread/fn.available_parallelism.html
267+
[result-copied]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.copied
268+
[result-cloned]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.cloned
269+
[option-copied]: https://doc.rust-lang.org/stable/std/result/enum.Option.html#method.copied
270+
[option-cloned]: https://doc.rust-lang.org/stable/std/result/enum.Option.html#method.cloned
271+
[asm]: https://doc.rust-lang.org/stable/core/arch/macro.asm.html
272+
[global_asm]: https://doc.rust-lang.org/stable/core/arch/macro.global_asm.html
273+
[is_break]: https://doc.rust-lang.org/stable/std/ops/enum.ControlFlow.html#method.is_break
274+
[is_continue]: https://doc.rust-lang.org/stable/std/ops/enum.ControlFlow.html#method.is_continue
275+
[try_from_char_u8]: https://doc.rust-lang.org/stable/std/primitive.char.html#impl-TryFrom%3Cchar%3E
276+
[zip]: https://doc.rust-lang.org/stable/std/iter/fn.zip.html
277+
[is_power_of_two8]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU8.html#method.is_power_of_two
278+
[is_power_of_two16]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU16.html#method.is_power_of_two
279+
[is_power_of_two32]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU32.html#method.is_power_of_two
280+
[is_power_of_two64]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU64.html#method.is_power_of_two
281+
[is_power_of_two128]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroU128.html#method.is_power_of_two
282+
[stdarch/1266]: https://github.com/rust-lang/stdarch/pull/1266

0 commit comments

Comments
 (0)