|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.68.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.68.0. Rust is a |
| 9 | +programming language empowering everyone to build reliable and efficient |
| 10 | +software. |
| 11 | + |
| 12 | +If you have a previous version of Rust installed via rustup, you can get 1.68.0 |
| 13 | +with: |
| 14 | + |
| 15 | +```console |
| 16 | +rustup update stable |
| 17 | +``` |
| 18 | + |
| 19 | +If you don't have it already, you can [get |
| 20 | +`rustup`](https://www.rust-lang.org/install.html) from the appropriate page on |
| 21 | +our website, and check out the [detailed release notes for |
| 22 | +1.68.0](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1680-2023-03-09) |
| 23 | +on GitHub. |
| 24 | + |
| 25 | +If you'd like to help us out by testing future releases, you might consider |
| 26 | +updating locally to use the beta channel (`rustup default beta`) or the nightly |
| 27 | +channel (`rustup default nightly`). Please |
| 28 | +[report](https://github.com/rust-lang/rust/issues/new/choose) any bugs you |
| 29 | +might come across! |
| 30 | + |
| 31 | +## What's in 1.68.0 stable |
| 32 | + |
| 33 | +### Cargo's sparse protocol |
| 34 | + |
| 35 | +Cargo's "sparse" registry protocol has been stabilized for reading the index of |
| 36 | +crates, along with infrastructure at `https://index.crates.io/` for those |
| 37 | +published in the primary crates.io registry. The prior git protocol (which is |
| 38 | +still the default) clones a repository that indexes _all_ crates available in |
| 39 | +the registry, but this has started to hit scaling limitations, with noticeable |
| 40 | +delays while updating that repository. The new protocol should provide a |
| 41 | +significant performance improvement when accessing crates.io, as it will only |
| 42 | +download information about the subset of crates that you actually use. |
| 43 | + |
| 44 | +To use the sparse protocol with crates.io, set the environment variable |
| 45 | +`CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse`, or edit your |
| 46 | +[`.cargo/config.toml` file](https://doc.rust-lang.org/cargo/reference/config.html) |
| 47 | +to add: |
| 48 | + |
| 49 | +```toml |
| 50 | +[registries.crates-io] |
| 51 | +protocol = "sparse" |
| 52 | +``` |
| 53 | + |
| 54 | +The sparse protocol is currently planned to become the default for crates.io in |
| 55 | +the 1.70.0 release in a few months. For more information, please see the prior |
| 56 | +[announcement](https://blog.rust-lang.org/inside-rust/2023/01/30/cargo-sparse-protocol.html) |
| 57 | +on the Inside Rust Blog, as well as |
| 58 | +[RFC 2789](https://rust-lang.github.io/rfcs/2789-sparse-index.html) |
| 59 | +and the current |
| 60 | +[documentation](https://doc.rust-lang.org/stable/cargo/reference/registry-index.html#sparse-protocol) |
| 61 | +in the Cargo Book. |
| 62 | + |
| 63 | +### Local `Pin` construction |
| 64 | + |
| 65 | +The new [`pin!`](https://doc.rust-lang.org/stable/std/pin/macro.pin.html) macro |
| 66 | +constructs a `Pin<&mut T>` from a `T` expression, anonymously captured in local |
| 67 | +state. This is often called stack-pinning, but that "stack" could also be the |
| 68 | +captured state of an `async fn` or block. This macro is similar to some crates, |
| 69 | +like [`tokio::pin!`](https://docs.rs/tokio/1/tokio/macro.pin.html), but the |
| 70 | +standard library can take advantage of `Pin` internals and [temporary lifetime |
| 71 | +extension](https://doc.rust-lang.org/stable/reference/destructors.html#temporary-lifetime-extension) |
| 72 | +for a more expression-like macro. |
| 73 | + |
| 74 | +```rust |
| 75 | +/// Runs a future to completion. |
| 76 | +fn block_on<F: Future>(future: F) -> F::Output { |
| 77 | + let waker_that_unparks_thread = todo!(); |
| 78 | + let mut cx = Context::from_waker(&waker_that_unparks_thread); |
| 79 | + // Pin the future so it can be polled. |
| 80 | + let mut pinned_future = pin!(future); |
| 81 | + loop { |
| 82 | + match pinned_future.as_mut().poll(&mut cx) { |
| 83 | + Poll::Pending => thread::park(), |
| 84 | + Poll::Ready(result) => return result, |
| 85 | + } |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +In this example, the original `future` will be moved into a temporary local, |
| 91 | +referenced by the new `pinned_future` with type `Pin<&mut F>`, and that pin is |
| 92 | +subject to the normal borrow checker to make sure it can't outlive that local. |
| 93 | + |
| 94 | +### Default `alloc` error handler |
| 95 | + |
| 96 | +When allocation fails in Rust, APIs like `Box::new` and `Vec::push` have no way |
| 97 | +to indicate that failure, so some divergent execution path needs to be taken. |
| 98 | +When using the `std` crate, the program will print to `stderr` and abort. |
| 99 | +As of Rust 1.68.0, binaries which include `std` will continue to have |
| 100 | +this behavior. Binaries which do not include `std`, only including `alloc`, will now `panic!` |
| 101 | +on allocation failure, which may be further adjusted via a `#[panic_handler]` if desired. |
| 102 | + |
| 103 | +In the future, it's likely that the behavior for `std` will also be changed to match that of `alloc`-only binaries. |
| 104 | + |
| 105 | +### Stabilized APIs |
| 106 | + |
| 107 | +- [`{core,std}::pin::pin!`](https://doc.rust-lang.org/stable/std/pin/macro.pin.html) |
| 108 | +- [`impl From<bool> for {f32,f64}`](https://doc.rust-lang.org/stable/std/primitive.f32.html#impl-From%3Cbool%3E-for-f32) |
| 109 | +- [`std::path::MAIN_SEPARATOR_STR`](https://doc.rust-lang.org/stable/std/path/constant.MAIN_SEPARATOR_STR.html) |
| 110 | +- [`impl DerefMut for PathBuf`](https://doc.rust-lang.org/stable/std/path/struct.PathBuf.html#impl-DerefMut-for-PathBuf) |
| 111 | + |
| 112 | +These APIs are now stable in const contexts: |
| 113 | + |
| 114 | +- [`VecDeque::new`](https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.new) |
| 115 | + |
| 116 | +### Other changes |
| 117 | + |
| 118 | +* As [previously announced](https://blog.rust-lang.org/2023/01/09/android-ndk-update-r25.html), |
| 119 | + Android platform support in Rust is now targeting NDK r25, which corresponds to |
| 120 | + a minimum supported API level of 19 (KitKat). |
| 121 | + |
| 122 | +Check out everything that changed in |
| 123 | +[Rust](https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-1680-2023-03-09), |
| 124 | +[Cargo](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-168-2023-03-09), |
| 125 | +and [Clippy](https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-168). |
| 126 | + |
| 127 | +### Contributors to 1.68.0 |
| 128 | + |
| 129 | +Many people came together to create Rust 1.68.0. |
| 130 | +We couldn't have done it without all of you. |
| 131 | +[Thanks!](https://thanks.rust-lang.org/rust/1.68.0/) |
0 commit comments