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.
If you have a previous version of Rust installed via rustup, you can get 1.70.0 with:
$ rustup update stable
If you don't have it already, you can get rustup
from the appropriate page on our website, and check out the detailed release notes for 1.70.0 on GitHub.
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 any bugs you might come across!
What's in 1.70.0 stable
Sparse by default for crates.io
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, 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!
You should see substantially improved performance when fetching information from the crates.io index. Users behind a restrictive firewall will need to ensure that access to https://index.crates.io
is available. If for some reason you need to stay with the previous default of using the git index hosted by GitHub, the registries.crates-io.protocol
config setting can be used to change the default.
One side-effect to note about changing the access method is that this also changes the path to the crate cache, so dependencies will be downloaded anew. Once you have fully committed to using the sparse protocol, you may want to clear out the old $CARGO_HOME/registry/*/github.com-*
paths.
OnceCell
and OnceLock
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.
use std::sync::OnceLock;
static WINNER: OnceLock<&str> = OnceLock::new();
fn main() {
let winner = std::thread::scope(|s| {
s.spawn(|| WINNER.set("thread"));
std::thread::yield_now(); // give them a chance...
WINNER.get_or_init(|| "main")
});
println!("{winner} wins!");
}
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.
IsTerminal
This newly-stabilized trait has a single method, is_terminal
, to determine if a given file descriptor or handle represents a terminal or TTY. This is another case of standardizing functionality that existed in external crates, like atty
and is-terminal
, using the C library isatty
function on Unix targets and similar functionality elsewhere. A common use case is for programs to distinguish between running in scripts or interactive modes, like presenting colors or even a full TUI when interactive.
use std::io::{stdout, IsTerminal};
fn main() {
let use_color = stdout().is_terminal();
// if so, add color codes to program output...
}
Named levels of debug information
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".
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.
Note that these named options are not yet available to be used via Cargo.toml
. Support for that will be available in the next release 1.71.
test
CLI
Enforced stability in the 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.
There are known cases where unstable options may have been used without direct user knowledge, especially --format json
used in IntelliJ Rust and other IDE plugins. Those projects are already adjusting to this change, and the status of JSON output can be followed in its tracking issue.
Stabilized APIs
NonZero*::MIN/MAX
BinaryHeap::retain
Default for std::collections::binary_heap::IntoIter
Default for std::collections::btree_map::{IntoIter, Iter, IterMut}
Default for std::collections::btree_map::{IntoKeys, Keys}
Default for std::collections::btree_map::{IntoValues, Values}
Default for std::collections::btree_map::Range
Default for std::collections::btree_set::{IntoIter, Iter}
Default for std::collections::btree_set::Range
Default for std::collections::linked_list::{IntoIter, Iter, IterMut}
Default for std::vec::IntoIter
Default for std::iter::Chain
Default for std::iter::Cloned
Default for std::iter::Copied
Default for std::iter::Enumerate
Default for std::iter::Flatten
Default for std::iter::Fuse
Default for std::iter::Rev
Default for std::slice::Iter
Default for std::slice::IterMut
Rc::into_inner
Arc::into_inner
std::cell::OnceCell
Option::is_some_and
NonNull::slice_from_raw_parts
Result::is_ok_and
Result::is_err_and
std::sync::atomic::Atomic*::as_ptr
std::io::IsTerminal
std::os::linux::net::SocketAddrExt
std::os::unix::net::UnixDatagram::bind_addr
std::os::unix::net::UnixDatagram::connect_addr
std::os::unix::net::UnixDatagram::send_to_addr
std::os::unix::net::UnixListener::bind_addr
std::path::Path::as_mut_os_str
std::sync::OnceLock
Other changes
Check out everything that changed in Rust, Cargo, and Clippy.
Contributors to 1.70.0
Many people came together to create Rust 1.70.0. We couldn't have done it without all of you. Thanks!