The Rust team is happy to announce a new version of Rust, 1.68.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.68.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.68.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.68.0 stable
Cargo’s sparse protocol
Cargo’s “sparse” registry protocol has been stabilized for reading the index of crates, along with infrastructure at https://index.crates.io/
for those published in the primary crates.io registry. The prior git protocol (which is still the default) clones a repository that indexes all crates available in the registry, but this has started to hit scaling limitations, with noticeable delays while updating that repository. The new protocol should provide a significant performance improvement when accessing crates.io, as it will only download information about the subset of crates that you actually use.
To use the sparse protocol with crates.io, set the environment variable CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
, or edit your .cargo/config.toml
file to add:
[registries.crates-io]
protocol = "sparse"
The sparse protocol is currently planned to become the default for crates.io in the 1.70.0 release in a few months. For more information, please see the prior announcement on the Inside Rust Blog, as well as RFC 2789 and the current documentation in the Cargo Book.
Local Pin
construction
The new pin!
macro constructs a Pin<&mut T>
from a T
expression, anonymously captured in local state. This is often called stack-pinning, but that “stack” could also be the captured state of an async fn
or block. This macro is similar to some crates, like tokio::pin!
, but the standard library can take advantage of Pin
internals and temporary lifetime extension for a more expression-like macro.
/// Runs a future to completion.
fn block_on<F: Future>(future: F) -> F::Output {
let waker_that_unparks_thread = todo!();
let mut cx = Context::from_waker(&waker_that_unparks_thread);
// Pin the future so it can be polled.
let mut pinned_future = pin!(future);
loop {
match pinned_future.as_mut().poll(&mut cx) {
Poll::Pending => thread::park(),
Poll::Ready(result) => return result,
}
}
}
In this example, the original future
will be moved into a temporary local, referenced by the new pinned_future
with type Pin<&mut F>
, and that pin is subject to the normal borrow checker to make sure it can’t outlive that local.
Default alloc
error handler
When allocation fails in Rust, APIs like Box::new
and Vec::push
have no way to indicate that failure, so some divergent execution path needs to be taken. When using the std
crate, the program will print to stderr
and abort. As of Rust 1.68.0, binaries which include std
will continue to have this behavior. Binaries which do not include std
, only including alloc
, will now panic!
on allocation failure, which may be further adjusted via a #[panic_handler]
if desired.
In the future, it’s likely that the behavior for std
will also be changed to match that of alloc
-only binaries.
Stabilized APIs
{core,std}::pin::pin!
impl From<bool> for {f32,f64}
std::path::MAIN_SEPARATOR_STR
impl DerefMut for PathBuf
These APIs are now stable in const contexts:
Other changes
- As previously announced, Android platform support in Rust is now targeting NDK r25, which corresponds to a minimum supported API level of 19 (KitKat).
Check out everything that changed in Rust, Cargo, and Clippy.
Contributors to 1.68.0
Many people came together to create Rust 1.68.0. We couldn’t have done it without all of you. Thanks!