Skip to content

Commit ac77f45

Browse files
committed
Release notes for Rust 1.50.0
1 parent f850d46 commit ac77f45

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

posts/2021-02-11-Rust-1.50.0.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
layout: post
3+
title: "Announcing Rust 1.50.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.50.0. Rust is a
9+
programming language that is empowering everyone to build reliable and
10+
efficient software.
11+
12+
If you have a previous version of Rust installed via rustup, getting Rust
13+
1.50.0 is as easy as:
14+
15+
```console
16+
rustup update stable
17+
```
18+
19+
If you don't have it already, you can [get `rustup`][install]
20+
from the appropriate page on our website, and check out the
21+
[detailed release notes for 1.50.0][notes] on GitHub.
22+
23+
[install]: https://www.rust-lang.org/install.html
24+
[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1500-2021-02-11
25+
26+
## What's in 1.50.0 stable
27+
28+
For this release, we have improved array indexing, expanded union field safety, refined file descriptors, and new library additions.
29+
See the [detailed release notes][notes] to learn about other changes
30+
not covered by this post.
31+
32+
### Const-generic array indexing
33+
34+
Continuing the march toward stable `const` generics, this release adds
35+
implementations of `ops::Index` and `IndexMut` for arrays `[T; N]` for
36+
_any_ length of `const N`. The indexing operator `[]` already worked on
37+
arrays through built-in compiler magic, but at the type level, arrays
38+
didn't actually implement the library traits until now.
39+
40+
```rust
41+
fn second<C>(container: &C) -> &C::Output
42+
where
43+
C: std::ops::Index<usize> + ?Sized,
44+
{
45+
&container[1]
46+
}
47+
48+
fn main() {
49+
let array: [i32; 3] = [1, 2, 3];
50+
assert_eq!(second(&array[..]), &2); // slices worked before
51+
assert_eq!(second(&array), &2); // now it also works directly
52+
}
53+
```
54+
55+
### Safe assignments to `ManuallyDrop<T>` union fields
56+
57+
Rust 1.49 made it possible to add `ManuallyDrop<T>` fields to a `union`
58+
as part of allowing `Drop` for unions at all; however, unions don't know
59+
which variant is valid (they don't drop any old value on assignment), so
60+
safe Rust has limited this to `Copy` types only, which never `Drop`. Of
61+
course, that's also true of `ManuallyDrop`, so now Rust 1.50 allows safe
62+
assignments to these fields as well.
63+
64+
### A niche for `File` on Unix platforms
65+
66+
Some types in Rust have specific limitations on what is considered
67+
valid value, which may not cover the entire range of possible memory
68+
values. We call any remaining invalid value a [niche], and this space
69+
may be used for type layout optimizations. For example, in Rust 1.28
70+
we introduced `NonZero` types where `0` is a niche, and this allowed
71+
`Option<NonZero>` to use `0` to represent `None` with no extra memory.
72+
73+
On Unix platforms, Rust's `File` is simply made of the system's integer
74+
file descriptor, and this happens to have a possible niche
75+
as well because it can never be `-1`! System calls which return a file
76+
descriptor use `-1` to indicate that an error occurred (check `errno`)
77+
so it's never possible for `-1` to be a real file descriptor. Starting
78+
in Rust 1.50 this niche is represented to the compiler so it can be
79+
use in layout optimizations too. It follows that `Option<File>` will
80+
now have the same size as `File` itself!
81+
82+
[niche]: https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#niche
83+
84+
### Library changes
85+
86+
In Rust 1.50.0, there are nine new stable functions:
87+
88+
- [`bool::then`]
89+
- [`btree_map::Entry::or_insert_with_key`]
90+
- [`f32::clamp`]
91+
- [`f64::clamp`]
92+
- [`hash_map::Entry::or_insert_with_key`]
93+
- [`Ord::clamp`]
94+
- [`RefCell::take`]
95+
- [`slice::fill`]
96+
- [`UnsafeCell::get_mut`]
97+
98+
And quite a few existing functions were made `const`:
99+
100+
- [`IpAddr::is_ipv4`]
101+
- [`IpAddr::is_ipv6`]
102+
- [`Layout::size`]
103+
- [`Layout::align`]
104+
- [`Layout::from_size_align`]
105+
- `pow` for all integer types.
106+
- `checked_pow` for all integer types.
107+
- `saturating_pow` for all integer types.
108+
- `wrapping_pow` for all integer types.
109+
- `next_power_of_two` for all unsigned integer types.
110+
- `checked_power_of_two` for all unsigned integer types.
111+
112+
See the [detailed release notes][notes] to learn about other changes.
113+
114+
[`IpAddr::is_ipv4`]: https://doc.rust-lang.org/stable/std/net/enum.IpAddr.html#method.is_ipv4
115+
[`IpAddr::is_ipv6`]: https://doc.rust-lang.org/stable/std/net/enum.IpAddr.html#method.is_ipv6
116+
[`Layout::align`]: https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.align
117+
[`Layout::from_size_align`]: https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.from_size_align
118+
[`Layout::size`]: https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.size
119+
[`Ord::clamp`]: https://doc.rust-lang.org/stable/std/cmp/trait.Ord.html#method.clamp
120+
[`RefCell::take`]: https://doc.rust-lang.org/stable/std/cell/struct.RefCell.html#method.take
121+
[`UnsafeCell::get_mut`]: https://doc.rust-lang.org/stable/std/cell/struct.UnsafeCell.html#method.get_mut
122+
[`bool::then`]: https://doc.rust-lang.org/stable/std/primitive.bool.html#method.then
123+
[`btree_map::Entry::or_insert_with_key`]: https://doc.rust-lang.org/stable/std/collections/btree_map/enum.Entry.html#method.or_insert_with_key
124+
[`f32::clamp`]: https://doc.rust-lang.org/stable/std/primitive.f32.html#method.clamp
125+
[`f64::clamp`]: https://doc.rust-lang.org/stable/std/primitive.f64.html#method.clamp
126+
[`hash_map::Entry::or_insert_with_key`]: https://doc.rust-lang.org/stable/std/collections/hash_map/enum.Entry.html#method.or_insert_with_key
127+
[`slice::fill`]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.fill
128+
129+
### Other changes
130+
131+
[relnotes-cargo]: https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-150-2021-02-11
132+
[relnotes-clippy]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-150
133+
134+
There are other changes in the Rust 1.50.0 release: check out what changed in
135+
[Rust][notes], [Cargo][relnotes-cargo], and [Clippy][relnotes-clippy].
136+
137+
## Contributors to 1.50.0
138+
139+
Many people came together to create Rust 1.50.0. We couldn't have done it
140+
without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.50.0/)

0 commit comments

Comments
 (0)