|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.77.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.77.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.77.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.77.0](https://doc.rust-lang.org/nightly/releases.html#version-77-2024-03-21). |
| 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.77.0 stable |
| 21 | + |
| 22 | +This release is relatively minor, but as always, even incremental improvements lead to a greater whole. A few of those changes are highlighted in this post, and others may yet fill more niche needs. |
| 23 | + |
| 24 | +### C-string literals |
| 25 | + |
| 26 | +Rust now supports C-string literals (`c"abc"`) which expand to a nul-byte |
| 27 | +terminated string in memory of type `&'static CStr`. This makes it easier to write code |
| 28 | +interoperating with foreign language interfaces which require nul-terminated |
| 29 | +strings, with all of the relevant error checking (e.g., lack of interior nul |
| 30 | +byte) performed at compile time. |
| 31 | + |
| 32 | +### Support for recursion in `async fn` |
| 33 | + |
| 34 | +Async functions previously could not call themselves due to a compiler |
| 35 | +limitation. In 1.77, that limitation has been lifted, so recursive calls are |
| 36 | +permitted so long as they use some form of indirection to avoid an infinite |
| 37 | +size for the state of the function. |
| 38 | + |
| 39 | +This means that code like this now works: |
| 40 | + |
| 41 | +```rust |
| 42 | +async fn fib(n: u32) -> u32 { |
| 43 | + match n { |
| 44 | + 0 | 1 => 1, |
| 45 | + _ => Box::pin(fib(n-1)).await + Box::pin(fib(n-2)).await |
| 46 | + } |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +### `offset_of!` |
| 51 | + |
| 52 | +1.77.0 stabilizes [`offset_of!`] for struct fields, which provides access to the |
| 53 | +byte offset of the relevant public field of a struct. This macro is most useful |
| 54 | +when the offset of a field is required without an existing instance of a type. |
| 55 | +Implementing such a macro is already possible on stable, but without an |
| 56 | +instance of the type the implementation would require tricky unsafe code which |
| 57 | +makes it easy to accidentally introduce undefined behavior. |
| 58 | + |
| 59 | +Users can now access the offset of a public field with `offset_of!(StructName, |
| 60 | +field)`. This expands to a `usize` expression with the offset in bytes from the |
| 61 | +start of the struct. |
| 62 | + |
| 63 | +[`offset_of!`]: https://doc.rust-lang.org/stable/std/mem/macro.offset_of.html |
| 64 | + |
| 65 | +### Enable strip in release profiles by default |
| 66 | + |
| 67 | +Cargo [profiles](https://doc.rust-lang.org/stable/cargo/reference/profiles.html) |
| 68 | +which do not enable [debuginfo](https://doc.rust-lang.org/stable/cargo/reference/profiles.html#debug) in |
| 69 | +outputs (e.g., `debug = 0`) will enable `strip = "debuginfo"` by default. |
| 70 | + |
| 71 | +This is primarily needed because the (precompiled) standard library ships with |
| 72 | +debuginfo, which means that statically linked results would include the |
| 73 | +debuginfo from the standard library even if the local compilations didn't |
| 74 | +explicitly request debuginfo. |
| 75 | + |
| 76 | +Users which do want debuginfo can explicitly enable it with the |
| 77 | +[debug](https://doc.rust-lang.org/stable/cargo/reference/profiles.html#debug) |
| 78 | +flag in the relevant Cargo profile. |
| 79 | + |
| 80 | +### Clippy adds a new `incompatible_msrv` lint |
| 81 | + |
| 82 | +The Rust project only supports the latest stable release of Rust. Some |
| 83 | +libraries aim to have an older minimum supported Rust version (MSRV), typically |
| 84 | +verifying this support by compiling in CI with an older release. However, when |
| 85 | +developing new code, it's convenient to use latest documentation and the latest |
| 86 | +toolchain with fixed bugs, performance improvements, and other improvements. |
| 87 | +This can make it easy to accidentally start using an API that's only available |
| 88 | +on newer versions of Rust. |
| 89 | + |
| 90 | +Clippy has added a new lint, [`incompatible_msrv`](https://rust-lang.github.io/rust-clippy/master/index.html#/incompatible_msrv), |
| 91 | +which will inform users if functionality being referenced is only available on |
| 92 | +newer versions than their |
| 93 | +[declared MSRV](https://github.com/rust-lang/rust-clippy/?tab=readme-ov-file#specifying-the-minimum-supported-rust-version). |
| 94 | + |
| 95 | +### Stabilized APIs |
| 96 | + |
| 97 | +- [`array::each_ref`](https://doc.rust-lang.org/stable/std/primitive.array.html#method.each_ref) |
| 98 | +- [`array::each_mut`](https://doc.rust-lang.org/stable/std/primitive.array.html#method.each_mut) |
| 99 | +- [`core::net`](https://doc.rust-lang.org/stable/core/net/index.html) |
| 100 | +- [`f32::round_ties_even`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.round_ties_even) |
| 101 | +- [`f64::round_ties_even`](https://doc.rust-lang.org/stable/std/primitive.f64.html#method.round_ties_even) |
| 102 | +- [`mem::offset_of!`](https://doc.rust-lang.org/stable/std/mem/macro.offset_of.html) |
| 103 | +- [`slice::first_chunk`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.first_chunk) |
| 104 | +- [`slice::first_chunk_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.first_chunk_mut) |
| 105 | +- [`slice::split_first_chunk`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_first_chunk) |
| 106 | +- [`slice::split_first_chunk_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_first_chunk_mut) |
| 107 | +- [`slice::last_chunk`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.last_chunk) |
| 108 | +- [`slice::last_chunk_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.last_chunk_mut) |
| 109 | +- [`slice::split_last_chunk`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_last_chunk) |
| 110 | +- [`slice::split_last_chunk_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_last_chunk_mut) |
| 111 | +- [`slice::chunk_by`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.chunk_by) |
| 112 | +- [`slice::chunk_by_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.chunk_by_mut) |
| 113 | +- [`Bound::map`](https://doc.rust-lang.org/stable/std/ops/enum.Bound.html#method.map) |
| 114 | +- [`File::create_new`](https://doc.rust-lang.org/stable/std/fs/struct.File.html#method.create_new) |
| 115 | +- [`Mutex::clear_poison`](https://doc.rust-lang.org/stable/std/sync/struct.Mutex.html#method.clear_poison) |
| 116 | +- [`RwLock::clear_poison`](https://doc.rust-lang.org/stable/std/sync/struct.RwLock.html#method.clear_poison) |
| 117 | + |
| 118 | +### Other changes |
| 119 | + |
| 120 | +Check out everything that changed in [Rust](https://github.com/rust-lang/rust/releases/tag/1.77.0), [Cargo](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-177-2024-03-21), and [Clippy](https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-177). |
| 121 | + |
| 122 | +## Contributors to 1.77.0 |
| 123 | + |
| 124 | +Many people came together to create Rust 1.77.0. We couldn't have done it without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.77.0/) |
0 commit comments