|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.70.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.70.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.70.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.70.0](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1700-2023-06-01) on GitHub. |
| 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.70.0 stable |
| 21 | + |
| 22 | +### Sparse by default for crates.io |
| 23 | + |
| 24 | +Cargo's "sparse" protocol is now enabled by default for reading the index from crates.io. This feature was previously stabilized with [Rust 1.68.0](https://blog.rust-lang.org/2023/03/09/Rust-1.68.0.html#cargos-sparse-protocol), but still required configuration to use that with crates.io. The announced plan was to make that the default in 1.70.0, and here it is! (TODO: maybe a statement about effects from user and infra sides?) |
| 25 | + |
| 26 | +### `OnceCell` and `OnceLock` |
| 27 | + |
| 28 | +Two new types have been stabilized for one-time initialization of shared data, `OnceCell` and its thread-safe counterpart `OnceLock`. These can be used anywhere that immediate construction is not wanted, and perhaps not even possible like non-`const` data in global variables. |
| 29 | + |
| 30 | +```rust |
| 31 | +use std::sync::OnceLock; |
| 32 | + |
| 33 | +fn main() { |
| 34 | + let winner_lock = OnceLock::new(); |
| 35 | + |
| 36 | + let winner = std::thread::scope(|s| { |
| 37 | + s.spawn(|| winner_lock.set("thread")); |
| 38 | + |
| 39 | + std::thread::yield_now(); // give them a chance... |
| 40 | + |
| 41 | + winner_lock.get_or_init(|| "main") |
| 42 | + }); |
| 43 | + |
| 44 | + println!("{winner} wins!"); |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +Crates such as `lazy_static` and `once_cell` have filled this need in the past, but now these building blocks are part of the standard library, ported from `once_cell`'s `unsync` and `sync` modules. There are still more methods that may be stabilized in the future, as well as companion `LazyCell` and `LazyLock` types that store their initializing function, but this first step in stabilization should already cover many use cases. |
| 49 | + |
| 50 | +### Named levels of debug information |
| 51 | + |
| 52 | +The `-Cdebuginfo` compiler option has previously only supported numbers 0..=2 for increasing amounts of debugging information, where Cargo defaults to 2 in dev and test profiles and 0 in release and bench profiles. These debug levels can now be set by name: "none" (0), "limited" (1), and "full" (2), as well as two new levels, "line-directives-only" and "line-tables-only". |
| 53 | + |
| 54 | +The Cargo and rustc documentation both called level 1 "line tables only" before, but it was more than that with information about all functions, just not types and variables. That level is now called "limited", and the new "line-tables-only" level is further reduced to the minimum needed for backtraces with filenames and line numbers. This may eventually become the level used for `-Cdebuginfo=1`. The other `line-directives-only` level is intended for NVPTX profiling, and is otherwise not recommended. |
| 55 | + |
| 56 | +### Enforced stability in the `test` CLI |
| 57 | + |
| 58 | +When `#[test]` functions are compiled, the executable gets a command-line interface from the `test` crate. This CLI has a number of options, including some that are not yet stabilized and require specifying `-Zunstable-options` as well, like many other commands in the Rust toolchain. However, while that's only intended to be allowed in nightly builds, that restriction wasn't active in `test` -- until now. Starting with 1.70.0, stable and beta builds of Rust will no longer allow unstable `test` options, making them truly nightly-only as documented. |
| 59 | + |
| 60 | +### Stabilized APIs |
| 61 | + |
| 62 | +- [`thing`](link) |
| 63 | + |
| 64 | +These APIs are now stable in const contexts: |
| 65 | + |
| 66 | +- [`const_thing`](link) |
| 67 | + |
| 68 | +### Other changes |
| 69 | + |
| 70 | +Check out everything that changed in [Rust](https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-1700-2023-06-01), [Cargo](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-1700-2023-06-01, and [Clippy](https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-170). |
| 71 | + |
| 72 | +## Contributors to 1.70.0 |
| 73 | + |
| 74 | +Many people came together to create Rust 1.70.0. We couldn't have done it without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.70.0/) |
0 commit comments