Skip to content

Commit 963397f

Browse files
tmandryMark-Simulacrum
authored andcommitted
Rust 1.59.0
1 parent 71e2096 commit 963397f

File tree

1 file changed

+276
-0
lines changed

1 file changed

+276
-0
lines changed

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

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

0 commit comments

Comments
 (0)