|
| 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 |
| 25 | +`#![no_std]` libraries. This primarily enables the wider Rust ecosystem to |
| 26 | +standardize on the same Error trait, regardless of what environments the |
| 27 | +library targets. |
| 28 | + |
| 29 | +### New sort implementations |
| 30 | + |
| 31 | +Both the stable and unstable sort implementations in the standard library have |
| 32 | +been updated to new algorithms, improving their runtime performance and |
| 33 | +compilation time. |
| 34 | + |
| 35 | +Additionally, both of the new sort algorithms try to detect incorrect |
| 36 | +implementations of `Ord` that prevent them from being able to produce a |
| 37 | +meaningfully sorted result, and will now panic on such cases rather than |
| 38 | +returning effectively randomly arranged data. Users encountering these panics |
| 39 | +should audit their ordering implementations to ensure they satisfy the |
| 40 | +requirements documented in [PartialOrd] and [Ord]. |
| 41 | + |
| 42 | +[PartialOrd]: https://doc.rust-lang.org/nightly/std/cmp/trait.PartialOrd.html |
| 43 | +[Ord]: https://doc.rust-lang.org/nightly/std/cmp/trait.Ord.html |
| 44 | + |
| 45 | +### `#[expect(lint)]` |
| 46 | + |
| 47 | +1.81 stabilizes a new lint level, `expect`, which allows explicitly noting that |
| 48 | +a particular lint *should* occur, and warning if it doesn't. The intended use |
| 49 | +case for this is temporarily silencing a lint, whether due to lint |
| 50 | +implementation bugs or ongoing refactoring, while wanting to know when the lint |
| 51 | +is no longer required. |
| 52 | + |
| 53 | +For example, if you're moving a code base to comply with a new restriction |
| 54 | +enforced via a Clippy lint like |
| 55 | +[`undocumented_unsafe_blocks`](https://rust-lang.github.io/rust-clippy/stable/index.html#/undocumented_unsafe_blocks), |
| 56 | +you can use `#[expect(clippy::undocumented_unsafe_blocks)]` as you transition, |
| 57 | +ensuring that once all unsafe blocks are documented you can opt into denying |
| 58 | +the lint to enforce it. |
| 59 | + |
| 60 | +Clippy also has two lints to enforce the usage of this feature and help with |
| 61 | +migrating existing attributes: |
| 62 | + |
| 63 | +* [`clippy::allow_attributes`](https://rust-lang.github.io/rust-clippy/master/index.html#/allow_attributes) to restrict allow attributes in favor of `#[expect]` or to migrate `#[allow]` attributes to `#[expect]` |
| 64 | +* [`clippy::allow_attributes_without_reason`](https://rust-lang.github.io/rust-clippy/master/index.html#/allow_attributes_without_reason) To require a reason for `#[allow]` attributes |
| 65 | + |
| 66 | +### Lint reasons |
| 67 | + |
| 68 | +Changing the lint level is often done for some particular reason. For example, |
| 69 | +if code runs in an environment without floating point support, you could use |
| 70 | +Clippy to lint on such usage with `#![deny(clippy::float_arithmetic)]`. |
| 71 | +However, if a new developer to the project sees this lint fire, they need to |
| 72 | +look for (hopefully) a comment on the deny explaining why it was added. With |
| 73 | +Rust 1.71, they can be informed directly in the compiler message: |
| 74 | + |
| 75 | +```text |
| 76 | +error: floating-point arithmetic detected |
| 77 | + --> src/lib.rs:4:5 |
| 78 | + | |
| 79 | +4 | a + b |
| 80 | + | ^^^^^ |
| 81 | + | |
| 82 | + = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic |
| 83 | + = note: no hardware float support |
| 84 | +note: the lint level is defined here |
| 85 | + --> src/lib.rs:1:9 |
| 86 | + | |
| 87 | +1 | #![deny(clippy::float_arithmetic, reason = "no hardware float support")] |
| 88 | + | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 89 | +``` |
| 90 | + |
| 91 | +### Stabilized APIs |
| 92 | + |
| 93 | +- [`core::error`](https://doc.rust-lang.org/stable/core/error/index.html) |
| 94 | +- [`hint::assert_unchecked`](https://doc.rust-lang.org/stable/core/hint/fn.assert_unchecked.html) |
| 95 | +- [`fs::exists`](https://doc.rust-lang.org/stable/std/fs/fn.exists.html) |
| 96 | +- [`AtomicBool::fetch_not`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.AtomicBool.html#method.fetch_not) |
| 97 | +- [`Duration::abs_diff`](https://doc.rust-lang.org/stable/core/time/struct.Duration.html#method.abs_diff) |
| 98 | +- [`IoSlice::advance`](https://doc.rust-lang.org/stable/std/io/struct.IoSlice.html#method.advance) |
| 99 | +- [`IoSlice::advance_slices`](https://doc.rust-lang.org/stable/std/io/struct.IoSlice.html#method.advance_slices) |
| 100 | +- [`IoSliceMut::advance`](https://doc.rust-lang.org/stable/std/io/struct.IoSliceMut.html#method.advance) |
| 101 | +- [`IoSliceMut::advance_slices`](https://doc.rust-lang.org/stable/std/io/struct.IoSliceMut.html#method.advance_slices) |
| 102 | +- [`PanicHookInfo`](https://doc.rust-lang.org/stable/std/panic/struct.PanicHookInfo.html) |
| 103 | +- [`PanicInfo::message`](https://doc.rust-lang.org/stable/core/panic/struct.PanicInfo.html#method.message) |
| 104 | +- [`PanicMessage`](https://doc.rust-lang.org/stable/core/panic/struct.PanicMessage.html) |
| 105 | + |
| 106 | +These APIs are now stable in const contexts: |
| 107 | + |
| 108 | +- [`char::from_u32_unchecked`](https://doc.rust-lang.org/stable/core/char/fn.from_u32_unchecked.html) (function) |
| 109 | +- [`char::from_u32_unchecked`](https://doc.rust-lang.org/stable/core/primitive.char.html#method.from_u32_unchecked) (method) |
| 110 | +- [`CStr::count_bytes`](https://doc.rust-lang.org/stable/core/ffi/c_str/struct.CStr.html#method.count_bytes) |
| 111 | +- [`CStr::from_ptr`](https://doc.rust-lang.org/stable/core/ffi/c_str/struct.CStr.html#method.from_ptr) |
| 112 | + |
| 113 | +### Compatibility notes |
| 114 | + |
| 115 | +#### Split panic hook and panic handler arguments |
| 116 | + |
| 117 | +We have renamed [`std::panic::PanicInfo`] to [`std::panic::PanicHookInfo`]. The old |
| 118 | +name will continue to work as an alias, but will result in a deprecation |
| 119 | +warning starting in Rust 1.82.0. |
| 120 | + |
| 121 | +`core::panic::PanicInfo` will remain unchanged, however, as this is now a |
| 122 | +*different type*. cuviper marked this conversation as resolved. |
| 123 | + |
| 124 | + The reason is that these types have different roles: |
| 125 | +`std::panic::PanicHookInfo` is the argument to the [panic hook](https://doc.rust-lang.org/stable/std/panic/fn.set_hook.html) in std |
| 126 | +context (where panics can have an arbitrary payload), while |
| 127 | +`core::panic::PanicInfo` is the argument to the |
| 128 | +[`#[panic_handler]`](https://doc.rust-lang.org/nomicon/panic-handler.html) in |
| 129 | +`#![no_std]` context (where panics always carry a formatted *message*). Separating |
| 130 | +these types allows us to add more useful methods to these types, such as |
| 131 | +[`std::panic::PanicHookInfo::payload_as_str()`]() and |
| 132 | +[`core::panic::PanicInfo::message()`](https://doc.rust-lang.org/stable/core/panic/struct.PanicInfo.html#method.message). |
| 133 | + |
| 134 | +[`std::panic::PanicInfo`]: https://doc.rust-lang.org/stable/std/panic/type.PanicInfo.html |
| 135 | +[`std::panic::PanicHookInfo`]: https://doc.rust-lang.org/stable/std/panic/type.PanicHookInfo.html |
| 136 | + |
| 137 | +#### Abort on uncaught panics in `extern "C"` functions |
| 138 | + |
| 139 | +This completes the transition started in [1.71](https://blog.rust-lang.org/2023/07/13/Rust-1.71.0.html#c-unwind-abi), |
| 140 | +which added dedicated `"C-unwind"` (amongst other `-unwind` variants) ABIs for |
| 141 | +when unwinding across the ABI boundary is expected. As of 1.81, the non-unwind |
| 142 | +ABIs (e.g., `"C"`) will now abort on uncaught unwinds, closing the longstanding |
| 143 | +soundess problem. |
| 144 | + |
| 145 | +Programs relying on unwinding should transition to using `-unwind` suffixed ABI |
| 146 | +variants. |
| 147 | + |
| 148 | +#### WASI 0.1 target naming changed |
| 149 | + |
| 150 | +Usage of the `wasm32-wasi` target (which targets WASI 0.1) will now issue a |
| 151 | +compiler warning and request users switch to the `wasm32-wasip1` target |
| 152 | +instead. Both targets are the same, `wasm32-wasi` is only being renamed, and |
| 153 | +this [change to the WASI target](https://blog.rust-lang.org/2024/04/09/updates-to-rusts-wasi-targets.html) |
| 154 | +is being done to enable removing `wasm32-wasi` in January 2025. |
| 155 | + |
| 156 | +The `wasm32-wasip2` target, which targets WASI 0.2, is now also a tier 2 target. |
| 157 | +See [the announcement post](https://blog.rust-lang.org/2024/09/05/wasip2-tier-2.html) for more details. |
| 158 | + |
| 159 | +#### Fixes CVE-2024-43402 |
| 160 | + |
| 161 | +`std::process::Command` now correctly escapes arguments when invoking batch |
| 162 | +files on Windows in the presence of trailing whitespace or periods (which are |
| 163 | +ignored and stripped by Windows). |
| 164 | + |
| 165 | +See more details in the previous [announcement of this change](https://blog.rust-lang.org/2024/09/04/cve-2024-43402.html). |
| 166 | + |
| 167 | +### Other changes |
| 168 | + |
| 169 | +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). |
| 170 | + |
| 171 | +## Contributors to 1.81.0 |
| 172 | + |
| 173 | +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