|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.81.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.81.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.81.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.81.0](https://doc.rust-lang.org/nightly/releases.html#version-1810-2024-09-05). |
| 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.81.0 stable |
| 21 | + |
| 22 | +### `core::error::Error` |
| 23 | + |
| 24 | +1.81 stabilizes the `Error` trait in `core`, allowing usage of the trait in `#![no_std]` libraries. |
| 25 | + |
| 26 | +TODO: What can we actually say about this? It seems like this mostly enables |
| 27 | +things in the ecosystem, but from the langauge/standard library not much has |
| 28 | +actually changed in *this* release? |
| 29 | + |
| 30 | +### New sort implementations |
| 31 | + |
| 32 | +Both the stable and unstable sort implementations in the standard library have |
| 33 | +been updated to new algorithms, improving their runtime performance and |
| 34 | +compilation time. Both of the new sort algorithms try to detect |
| 35 | +incorrect implementations of `Ord` and will panic on such cases if detected. |
| 36 | + |
| 37 | +Users encountering these panics should audit any custom Ord implementations to |
| 38 | +ensure they satisfy the requirements documented in [PartialOrd] and [Ord]. |
| 39 | + |
| 40 | +TODO: Ideally we'd have text somewhere specific to the new detection that helps |
| 41 | +explain how to do this audit or otherwise helps users. This otherwise feels |
| 42 | +pretty opaque to me. We might also want to consider whether some kind of |
| 43 | +transition rather than panic! is best (not sure how else users would find out |
| 44 | +about the problem though). See https://github.com/rust-lang/rust/issues/129561. |
| 45 | + |
| 46 | +[PartialOrd]: https://doc.rust-lang.org/nightly/std/cmp/trait.PartialOrd.html |
| 47 | +[Ord]: https://doc.rust-lang.org/nightly/std/cmp/trait.Ord.html |
| 48 | + |
| 49 | +### `#[expect(lint)]` |
| 50 | + |
| 51 | +1.81 stabilizes a new lint level, `expect`, which allows explicitly noting that |
| 52 | +a particular lint *should* occur, and warning if it doesn't. The intended use |
| 53 | +case for this is temporarily silencing a lint, whether due to lint |
| 54 | +implementation bugs or ongoing refactoring, while wanting to know when the lint |
| 55 | +is no longer required. |
| 56 | + |
| 57 | +For example, if you're moving a code base to comply with a new restriction |
| 58 | +enforced via a Clippy lint like |
| 59 | +[`undocumented_unsafe_blocks`](https://rust-lang.github.io/rust-clippy/stable/index.html#/undocumented_unsafe_blocks), |
| 60 | +you can use `#[expect(clippy::undocumented_unsafe_blocks)]` as you transition, |
| 61 | +ensuring that once all unsafe blocks are documented you can opt into denying |
| 62 | +the lint to enforce it. |
| 63 | + |
| 64 | +### Lint reasons |
| 65 | + |
| 66 | +Changing the lint level is often done for some particular reason. For example, |
| 67 | +if code runs in an environment without floating point support, you could use |
| 68 | +Clippy to lint on such usage with `#![deny(clippy::float_arithmetic)]`. |
| 69 | +However, if a new developer to the project sees this lint fire, they need to |
| 70 | +look for (hopefully) a comment on the deny explaining why it was added. With |
| 71 | +Rust 1.71, they can be informed directly in the compiler message: |
| 72 | + |
| 73 | +```text |
| 74 | +error: floating-point arithmetic detected |
| 75 | + --> src/lib.rs:4:5 |
| 76 | + | |
| 77 | +4 | a + b |
| 78 | + | ^^^^^ |
| 79 | + | |
| 80 | + = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic |
| 81 | + = note: no hardware float support |
| 82 | +note: the lint level is defined here |
| 83 | + --> src/lib.rs:1:9 |
| 84 | + | |
| 85 | +1 | #![deny(clippy::float_arithmetic, reason = "no hardware float support")] |
| 86 | + | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 87 | +``` |
| 88 | + |
| 89 | +### Stabilized APIs |
| 90 | + |
| 91 | +- [`core::error`](https://doc.rust-lang.org/stable/core/error/index.html) |
| 92 | +- [`hint::assert_unchecked`](https://doc.rust-lang.org/stable/core/hint/fn.assert_unchecked.html) |
| 93 | +- [`fs::exists`](https://doc.rust-lang.org/stable/std/fs/fn.exists.html) |
| 94 | +- [`AtomicBool::fetch_not`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicBool.html#method.fetch_not) |
| 95 | +- [`Duration::abs_diff`](https://doc.rust-lang.org/stable/core/time/struct.Duration.html#method.abs_diff) |
| 96 | +- [`IoSlice::advance`](https://doc.rust-lang.org/stable/std/io/struct.IoSlice.html#method.advance) |
| 97 | +- [`IoSlice::advance_slices`](https://doc.rust-lang.org/stable/std/io/struct.IoSlice.html#method.advance_slices) |
| 98 | +- [`IoSliceMut::advance`](https://doc.rust-lang.org/stable/std/io/struct.IoSliceMut.html#method.advance) |
| 99 | +- [`IoSliceMut::advance_slices`](https://doc.rust-lang.org/stable/std/io/struct.IoSliceMut.html#method.advance_slices) |
| 100 | +- [`PanicHookInfo`](https://doc.rust-lang.org/stable/std/panic/struct.PanicHookInfo.html) |
| 101 | +- [`PanicInfo::message`](https://doc.rust-lang.org/stable/core/panic/struct.PanicInfo.html#method.message) |
| 102 | +- [`PanicMessage`](https://doc.rust-lang.org/stable/core/panic/struct.PanicMessage.html) |
| 103 | + |
| 104 | +These APIs are now stable in const contexts: |
| 105 | + |
| 106 | +- [`char::from_u32_unchecked`](https://doc.rust-lang.org/stable/core/char/fn.from_u32_unchecked.html) (function) |
| 107 | +- [`char::from_u32_unchecked`](https://doc.rust-lang.org/stable/core/primitive.char.html#method.from_u32_unchecked) (method) |
| 108 | +- [`CStr::count_bytes`](https://doc.rust-lang.org/stable/core/ffi/c_str/struct.CStr.html#method.count_bytes) |
| 109 | +- [`CStr::from_ptr`](https://doc.rust-lang.org/stable/core/ffi/c_str/struct.CStr.html#method.from_ptr) |
| 110 | + |
| 111 | +### Compatibility notes |
| 112 | + |
| 113 | +#### Split panic hook and panic handler arguments |
| 114 | + |
| 115 | +We have renamed [`std::panic::PanicInfo`] to [`std::panic::PanicHookInfo`]. The old |
| 116 | +name will continue to work as an alias, but will result in a deprecation |
| 117 | +warning starting in Rust 1.82.0. |
| 118 | + |
| 119 | +`core::panic::PanicInfo` will remain unchanged, however, as this is now a |
| 120 | +*different type*. cuviper marked this conversation as resolved. |
| 121 | + |
| 122 | + The reason is that these types have different roles: |
| 123 | +`std::panic::PanicHookInfo` is the argument to the [panic hook](https://doc.rust-lang.org/stable/std/panic/fn.set_hook.html) in std |
| 124 | +context (where panics can have an arbitrary payload), while |
| 125 | +`core::panic::PanicInfo` is the argument to the |
| 126 | +[`#[panic_handler]`](https://doc.rust-lang.org/nomicon/panic-handler.html) in |
| 127 | +`#![no_std]` context (where panics always carry a formatted *message*). Separating |
| 128 | +these types allows us to add more useful methods to these types, such as |
| 129 | +[`std::panic::PanicHookInfo::payload_as_str()`]() and |
| 130 | +[`core::panic::PanicInfo::message()`](https://doc.rust-lang.org/stable/core/panic/struct.PanicInfo.html#method.message). |
| 131 | + |
| 132 | +[`std::panic::PanicInfo`]: https://doc.rust-lang.org/stable/std/panic/type.PanicInfo.html |
| 133 | +[`std::panic::PanicHookInfo`]: https://doc.rust-lang.org/stable/std/panic/type.PanicHookInfo.html |
| 134 | + |
| 135 | +#### Abort on uncaught panics in `extern "C"` functions |
| 136 | + |
| 137 | +This completes the transition started in [1.71](https://blog.rust-lang.org/2023/07/13/Rust-1.71.0.html#c-unwind-abi), |
| 138 | +which added dedicated `"C-unwind"` (amongst other `-unwind` variants) ABIs for |
| 139 | +when unwinding across the ABI boundary is expected. As of 1.81, the non-unwind |
| 140 | +ABIs (e.g., `"C"`) will now abort on uncaught unwinds, closing the longstanding soundess problem. |
| 141 | + |
| 142 | +Programs relying on unwinding should transition to using `-unwind` suffixed ABI |
| 143 | +variants. |
| 144 | + |
| 145 | +TODO: Check on status of https://github.com/rust-lang/rust/issues/123231 |
| 146 | + |
| 147 | +#### WASI target naming changed |
| 148 | + |
| 149 | +Usage of the `wasm32-wasi` target will now issue a compiler warning and request |
| 150 | +users switch to the `wasm32-wasip1` target instead. Both targets are the same, |
| 151 | +`wasm32-wasi` is only being renamed, and this [change to the WASI target](https://blog.rust-lang.org/2024/04/09/updates-to-rusts-wasi-targets.html) |
| 152 | +is being done to enable removing `wasm32-wasi` in January 2025. |
| 153 | + |
| 154 | +### Other changes |
| 155 | + |
| 156 | +Check out everything that changed in [Rust](https://github.com/rust-lang/rust/releases/tag/1.81.0), [Cargo](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-181-2024-09-05), and [Clippy](https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-181). |
| 157 | + |
| 158 | +## Contributors to 1.81.0 |
| 159 | + |
| 160 | +Many people came together to create Rust 1.81.0. We couldn't have done it without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.81.0/) |
0 commit comments