What Is New in Rust 1.81
| Category | Highlights |
|---|---|
| New Features | core::error::Error stabilized for no_std; #[expect] lint level; lint reasons attribute; const-stable APIs |
| Improvements | New sort algorithms with better runtime and compile-time; panic hook type split; abort on uncaught panics in extern "C"; WASI target rename warning |
| Bug Fixes | Fix for CVE-2024-43402 in std::process::Command on Windows |
| Breaking Changes | std::panic::PanicInfo renamed to std::panic::PanicHookInfo (deprecation warning); uncaught panics in "C" ABI now abort; sort now panics on invalid Ord implementations |
| Deprecations | std::panic::PanicInfo alias will be deprecated starting 1.82 |
Can I now use the standard Error trait in no_std crates?
Yes, Rust 1.81 stabilizes core::error::Error, allowing you to implement the common Error trait in #![no_std] libraries.
- This unifies error handling across std and no_std ecosystems.
- Existing no_std crates can add
impl core::error::Error for MyError { ... }without pulling in the standard library. - Watch out for any code that still depends on the older
std::error::Errortrait; replace it with the core version to keep the crate truly no_std.
How do I temporarily silence a lint while still being warned if it disappears?
Use the newly stabilized #[expect] attribute to mark a lint as expected, which will emit a warning if the lint no longer fires.
#[expect(clippy::undocumented_unsafe_blocks)]
fn risky() {
// unsafe code here
}
- Ideal for incremental migrations where you want to track progress.
- Clippy provides
clippy::allow_attributesandclippy::allow_attributes_without_reasonto help migrate existing#[allow]attributes. - In practice, pair
#[expect]with a comment explaining the temporary nature of the exemption.
What changes affect sorting and panic handling in Rust 1.81?
Rust 1.81 introduces faster sort algorithms and separates panic hook types, improving both performance and ergonomics.
- Both stable and unstable sort now use new algorithms that reduce runtime and compile-time overhead.
- If an
Ordimplementation is incorrect, the sort will panic instead of producing nondeterministic order, helping you catch bugs early. - The panic hook argument type has been renamed to
std::panic::PanicHookInfo; the old name remains as an alias but will be deprecated in 1.82. - Uncaught panics in extern "C" functions now abort the process, closing a long-standing soundness issue. Switch to the
"C-unwind"ABI if you rely on unwinding.
Which security and platform updates should I be aware of in Rust 1.81?
Rust 1.81 addresses a Windows command-line vulnerability and updates the WASI target naming.
std::process::Commandnow correctly escapes arguments when invoking batch files with trailing whitespace or periods, fixing CVE-2024-43402.- The legacy
wasm32-wasitarget now emits a warning; migrate towasm32-wasip1to avoid future removal in January 2025. - These changes are automatic for most codebases, but double-check any custom Windows batch invocation logic and update your Cargo target triples accordingly.
Frequently Asked Questions
Does upgrading to Rust 1.81 require changes to existing no_std libraries?
Most no_std crates will continue to work, but you can now replace any std::error::Error usage with core::error::Error for a fully no_std implementation.
How can I use the new #[expect] attribute in my code?
Apply #[expect(clippy::lint_name)] above the item you want to silence, for example #[expect(clippy::undocumented_unsafe_blocks)] on a function.
Will my existing sort calls behave differently after upgrading?
If your Ord implementation violates the contract, the sort will now panic instead of silently producing incorrect order.
What should I do about the std::panic::PanicInfo rename?
Continue using std::panic::PanicInfo for now; the compiler will emit a deprecation warning in 1.82, so update to std::panic::PanicHookInfo when convenient.
Is there any action required for the WASI target warning?
Switch your Cargo target from wasm32-wasi to wasm32-wasip1 to silence the warning and prepare for the target removal.
How do I apply the Windows Command fix for CVE-2024-43402?
The fix is built into std::process::Command in Rust 1.81, so simply updating to the new compiler version applies the mitigation automatically.