Skip to content

Commit 4674d07

Browse files
tmandryMark-Simulacrum
authored andcommitted
Rust 1.59.0
1 parent 71e2096 commit 4674d07

File tree

1 file changed

+273
-0
lines changed

1 file changed

+273
-0
lines changed

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

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

0 commit comments

Comments
 (0)