Skip to content

Commit 1025943

Browse files
cuviperprogrammerjakekpreidUrgauMark-Simulacrum
authored
Announcing Rust 1.80.0 (#1358)
Co-authored-by: Jacob Lifshay <[email protected]> Co-authored-by: Kevin Reid <[email protected]> Co-authored-by: Urgau <[email protected]> Co-authored-by: Mark Rousskov <[email protected]>
1 parent c8d3a4a commit 1025943

File tree

1 file changed

+185
-0
lines changed

1 file changed

+185
-0
lines changed

posts/2024-07-25-Rust-1.80.0.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
---
2+
layout: post
3+
title: "Announcing Rust 1.80.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.80.0. Rust is a programming language empowering everyone to build reliable and efficient software.
9+
10+
If you have a previous version of Rust installed via `rustup`, you can get 1.80.0 with:
11+
12+
```console
13+
$ rustup update stable
14+
```
15+
16+
If you don't have it already, you can [get `rustup`](https://www.rust-lang.org/install.html) from the appropriate page on our website, and check out the [detailed release notes for 1.80.0](https://doc.rust-lang.org/nightly/releases.html#version-1800-2024-07-25).
17+
18+
If you'd like to help us out by testing future releases, you might consider updating locally to use the beta channel (`rustup default beta`) or the nightly channel (`rustup default nightly`). Please [report](https://github.com/rust-lang/rust/issues/new/choose) any bugs you might come across!
19+
20+
## What's in 1.80.0 stable
21+
22+
### `LazyCell` and `LazyLock`
23+
24+
These "lazy" types delay the initialization of their data until first access. They are similar to the `OnceCell` and `OnceLock` types [stabilized in 1.70](https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html#oncecell-and-oncelock), but with the initialization function included in the cell. This completes the stabilization of functionality adopted into the standard library from the popular [`lazy_static`](https://crates.io/crates/lazy-static) and [`once_cell`](https://crates.io/crates/once_cell) crates.
25+
26+
`LazyLock` is the thread-safe option, making it suitable for places like `static` values. For example, both the `spawn` thread and the main `scope` will see the exact same duration below, since `LAZY_TIME` will be initialized once, by whichever ends up accessing the static first. Neither use has to know *how* to initialize it, unlike they would with `OnceLock::get_or_init()`.
27+
28+
```rust
29+
use std::sync::LazyLock;
30+
use std::time::Instant;
31+
32+
static LAZY_TIME: LazyLock<Instant> = LazyLock::new(Instant::now);
33+
34+
fn main() {
35+
let start = Instant::now();
36+
std::thread::scope(|s| {
37+
s.spawn(|| {
38+
println!("Thread lazy time is {:?}", LAZY_TIME.duration_since(start));
39+
});
40+
println!("Main lazy time is {:?}", LAZY_TIME.duration_since(start));
41+
});
42+
}
43+
```
44+
45+
`LazyCell` does the same thing without thread synchronization, so it doesn't implement `Sync`, which is needed for `static`, but it can still be used in `thread_local!` statics (with distinct initialization per thread). Either type can also be used in other data structures as well, depending on thread-safety needs, so lazy initialization is available everywhere!
46+
47+
### Checked `cfg` names and values
48+
49+
In 1.79, `rustc` stabilized a [`--check-cfg` flag](https://doc.rust-lang.org/rustc/check-cfg.html), and now Cargo 1.80 is enabling those checks for all `cfg` names and values that it knows (in addition to the [well known names and values](https://doc.rust-lang.org/rustc/check-cfg.html#well-known-names-and-values) from `rustc`). This includes feature names from `Cargo.toml` as well as new `cargo::rustc-check-cfg` output from build scripts.
50+
51+
Unexpected cfgs are reported by the warn-by-default `unexpected_cfgs` lint, which is meant to catch typos or other misconfiguration. For example, in a project with an optional `rayon` dependency, this code is configured for the wrong `feature` value:
52+
53+
```rust
54+
fn main() {
55+
println!("Hello, world!");
56+
57+
#[cfg(feature = "crayon")]
58+
rayon::join(
59+
|| println!("Hello, Thing One!"),
60+
|| println!("Hello, Thing Two!"),
61+
);
62+
}
63+
```
64+
65+
```console
66+
warning: unexpected `cfg` condition value: `crayon`
67+
--> src/main.rs:4:11
68+
|
69+
4 | #[cfg(feature = "crayon")]
70+
| ^^^^^^^^^^--------
71+
| |
72+
| help: there is a expected value with a similar name: `"rayon"`
73+
|
74+
= note: expected values for `feature` are: `rayon`
75+
= help: consider adding `crayon` as a feature in `Cargo.toml`
76+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
77+
= note: `#[warn(unexpected_cfgs)]` on by default
78+
```
79+
80+
The same warning is reported regardless of whether the actual `rayon` feature is enabled or not.
81+
82+
The `[lints]` table in the `Cargo.toml` manifest can also be used to extend the list of known names and values for custom `cfg`. `rustc` automatically provides [the syntax](https://doc.rust-lang.org/rustc/check-cfg.html#specifying-expected-names-and-values) to use in the warning.
83+
84+
```toml
85+
[lints.rust]
86+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo, values("bar"))'] }
87+
```
88+
89+
You can read more about this feature in a [previous blog post](https://blog.rust-lang.org/2024/05/06/check-cfg.html) announcing the availability of the feature on nightly.
90+
91+
### Exclusive ranges in patterns
92+
93+
Rust ranged patterns can now use exclusive endpoints, written `a..b` or `..b` similar to the `Range` and `RangeTo` expression types. For example, the following patterns can now use the same constants for the end of one pattern and the start of the next:
94+
95+
```rust
96+
pub fn size_prefix(n: u32) -> &'static str {
97+
const K: u32 = 10u32.pow(3);
98+
const M: u32 = 10u32.pow(6);
99+
const G: u32 = 10u32.pow(9);
100+
match n {
101+
..K => "",
102+
K..M => "k",
103+
M..G => "M",
104+
G.. => "G",
105+
}
106+
}
107+
```
108+
109+
Previously, only inclusive (`a..=b` or `..=b`) or open (`a..`) ranges were allowed in patterns, so code like this would require separate constants for inclusive endpoints like `K - 1`.
110+
111+
Exclusive ranges have been implemented as an unstable feature for a long time, but the blocking concern was that they might add confusion and increase the chance of off-by-one errors in patterns. To that end, exhaustiveness checking has been enhanced to better detect gaps in pattern matching, and new lints `non_contiguous_range_endpoints` and `overlapping_range_endpoints` will help detect cases where you might want to switch exclusive patterns to inclusive, or vice versa.
112+
113+
### Stabilized APIs
114+
115+
- [`impl Default for Rc<CStr>`](https://doc.rust-lang.org/stable/alloc/rc/struct.Rc.html#impl-Default-for-Rc%3CCStr%3E)
116+
- [`impl Default for Rc<str>`](https://doc.rust-lang.org/stable/alloc/rc/struct.Rc.html#impl-Default-for-Rc%3Cstr%3E)
117+
- [`impl Default for Rc<[T]>`](https://doc.rust-lang.org/stable/alloc/rc/struct.Rc.html#impl-Default-for-Rc%3C%5BT%5D%3E)
118+
- [`impl Default for Arc<str>`](https://doc.rust-lang.org/stable/alloc/sync/struct.Arc.html#impl-Default-for-Arc%3Cstr%3E)
119+
- [`impl Default for Arc<CStr>`](https://doc.rust-lang.org/stable/alloc/sync/struct.Arc.html#impl-Default-for-Arc%3CCStr%3E)
120+
- [`impl Default for Arc<[T]>`](https://doc.rust-lang.org/stable/alloc/sync/struct.Arc.html#impl-Default-for-Arc%3C%5BT%5D%3E)
121+
- [`impl IntoIterator for Box<[T]>`](https://doc.rust-lang.org/stable/alloc/boxed/struct.Box.html#impl-IntoIterator-for-Box%3C%5BI%5D,+A%3E)
122+
- [`impl FromIterator<String> for Box<str>`](https://doc.rust-lang.org/stable/alloc/boxed/struct.Box.html#impl-FromIterator%3CString%3E-for-Box%3Cstr%3E)
123+
- [`impl FromIterator<char> for Box<str>`](https://doc.rust-lang.org/stable/alloc/boxed/struct.Box.html#impl-FromIterator%3Cchar%3E-for-Box%3Cstr%3E)
124+
- [`LazyCell`](https://doc.rust-lang.org/stable/core/cell/struct.LazyCell.html)
125+
- [`LazyLock`](https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html)
126+
- [`Duration::div_duration_f32`](https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.div_duration_f32)
127+
- [`Duration::div_duration_f64`](https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.div_duration_f64)
128+
- [`Option::take_if`](https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.take_if)
129+
- [`Seek::seek_relative`](https://doc.rust-lang.org/stable/std/io/trait.Seek.html#method.seek_relative)
130+
- [`BinaryHeap::as_slice`](https://doc.rust-lang.org/stable/std/collections/struct.BinaryHeap.html#method.as_slice)
131+
- [`NonNull::offset`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.offset)
132+
- [`NonNull::byte_offset`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.byte_offset)
133+
- [`NonNull::add`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.add)
134+
- [`NonNull::byte_add`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.byte_add)
135+
- [`NonNull::sub`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.sub)
136+
- [`NonNull::byte_sub`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.byte_sub)
137+
- [`NonNull::offset_from`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.offset_from)
138+
- [`NonNull::byte_offset_from`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.byte_offset_from)
139+
- [`NonNull::read`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.read)
140+
- [`NonNull::read_volatile`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.read_volatile)
141+
- [`NonNull::read_unaligned`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.read_unaligned)
142+
- [`NonNull::write`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.write)
143+
- [`NonNull::write_volatile`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.write_volatile)
144+
- [`NonNull::write_unaligned`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.write_unaligned)
145+
- [`NonNull::write_bytes`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.write_bytes)
146+
- [`NonNull::copy_to`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.copy_to)
147+
- [`NonNull::copy_to_nonoverlapping`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.copy_to_nonoverlapping)
148+
- [`NonNull::copy_from`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.copy_from)
149+
- [`NonNull::copy_from_nonoverlapping`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.copy_from_nonoverlapping)
150+
- [`NonNull::replace`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.replace)
151+
- [`NonNull::swap`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.swap)
152+
- [`NonNull::drop_in_place`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.drop_in_place)
153+
- [`NonNull::align_offset`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.align_offset)
154+
- [`<[T]>::split_at_checked`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_at_checked)
155+
- [`<[T]>::split_at_mut_checked`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_at_mut_checked)
156+
- [`str::split_at_checked`](https://doc.rust-lang.org/stable/std/primitive.str.html#method.split_at_checked)
157+
- [`str::split_at_mut_checked`](https://doc.rust-lang.org/stable/std/primitive.str.html#method.split_at_mut_checked)
158+
- [`str::trim_ascii`](https://doc.rust-lang.org/stable/std/primitive.str.html#method.trim_ascii)
159+
- [`str::trim_ascii_start`](https://doc.rust-lang.org/stable/std/primitive.str.html#method.trim_ascii_start)
160+
- [`str::trim_ascii_end`](https://doc.rust-lang.org/stable/std/primitive.str.html#method.trim_ascii_end)
161+
- [`<[u8]>::trim_ascii`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.trim_ascii)
162+
- [`<[u8]>::trim_ascii_start`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.trim_ascii_start)
163+
- [`<[u8]>::trim_ascii_end`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.trim_ascii_end)
164+
- [`Ipv4Addr::BITS`](https://doc.rust-lang.org/stable/core/net/struct.Ipv4Addr.html#associatedconstant.BITS)
165+
- [`Ipv4Addr::to_bits`](https://doc.rust-lang.org/stable/core/net/struct.Ipv4Addr.html#method.to_bits)
166+
- [`Ipv4Addr::from_bits`](https://doc.rust-lang.org/stable/core/net/struct.Ipv4Addr.html#method.from_bits)
167+
- [`Ipv6Addr::BITS`](https://doc.rust-lang.org/stable/core/net/struct.Ipv6Addr.html#associatedconstant.BITS)
168+
- [`Ipv6Addr::to_bits`](https://doc.rust-lang.org/stable/core/net/struct.Ipv6Addr.html#method.to_bits)
169+
- [`Ipv6Addr::from_bits`](https://doc.rust-lang.org/stable/core/net/struct.Ipv6Addr.html#method.from_bits)
170+
- [`Vec::<[T; N]>::into_flattened`](https://doc.rust-lang.org/stable/alloc/vec/struct.Vec.html#method.into_flattened)
171+
- [`<[[T; N]]>::as_flattened`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.as_flattened)
172+
- [`<[[T; N]]>::as_flattened_mut`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.as_flattened_mut)
173+
174+
These APIs are now stable in const contexts:
175+
176+
- [`<[T]>::last_chunk`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.last_chunk)
177+
- [`BinaryHeap::new`](https://doc.rust-lang.org/stable/std/collections/struct.BinaryHeap.html#method.new)
178+
179+
### Other changes
180+
181+
Check out everything that changed in [Rust](https://github.com/rust-lang/rust/releases/tag/1.80.0), [Cargo](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-180-2024-07-25), and [Clippy](https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-180).
182+
183+
## Contributors to 1.80.0
184+
185+
Many people came together to create Rust 1.80.0. We couldn't have done it without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.80.0/)

0 commit comments

Comments
 (0)