Announcing Rust 1.98.0

Announcing Rust 1.98.0

Rust 1.98.0 发布公告

Aug. 20, 2026 · The Rust Release Team 2026 年 8 月 20 日 · Rust 发布团队

The Rust team is happy to announce a new version of Rust, 1.98.0. Rust is a programming language empowering everyone to build reliable and efficient software. Rust 团队很高兴地宣布 Rust 的新版本 1.98.0。Rust 是一门旨在让每个人都能构建可靠且高效软件的编程语言。

If you have a previous version of Rust installed via rustup, you can get 1.98.0 with: $ rustup update stable 如果你已经通过 rustup 安装了旧版本的 Rust,可以通过以下命令获取 1.98.0:$ rustup update stable

If you don’t have it already, you can get rustup from the appropriate page on our website, and check out the detailed release notes for 1.98.0. 如果你还没有安装,可以从我们官网的相关页面获取 rustup,并查看 1.98.0 的详细发布说明。

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 any bugs you might come across! 如果你想通过测试未来版本来帮助我们,可以考虑在本地更新并使用 beta 通道(rustup default beta)或 nightly 通道(rustup default nightly)。如果遇到任何 Bug,请务必向我们报告!

What’s in 1.98.0 stable

Rust 1.98.0 稳定版更新内容

Algebraic floating-point methods

代数浮点数方法

The floating-point types f32 and f64 now have “algebraic” methods for addition, subtraction, multiplication, division, and remainder. These allow optimizations on these operations using the algebraic properties of real numbers, even though these properties do not hold with the limitations of floating-point representations. 浮点类型 f32 和 f64 现在拥有了用于加、减、乘、除和取余的“代数”方法。这些方法允许利用实数的代数性质对这些运算进行优化,尽管这些性质在浮点数表示的限制下并不完全成立。

The exact set of optimizations is not specified, but may be similar to the kind of optimization you would see with the -ffast-math option in other languages. For example, floating-point addition is not associative, so a sum like a + b + c + d must be evaluated in the left-associative order in which it is parsed, like ((a + b) + c) + d. If you write the same sum as a chain of algebraic_add calls, then the compiler is free to reorder it, perhaps like (a + b) + (c + d) to evaluate the partial sums simultaneously. 具体的优化集并未明确指定,但可能类似于其他语言中 -ffast-math 选项所带来的优化。例如,浮点加法不满足结合律,因此像 a + b + c + d 这样的求和必须按照解析时的左结合顺序进行计算,即 ((a + b) + c) + d。如果你将同样的求和写成一系列 algebraic_add 调用,编译器就可以自由地对其进行重排序,例如将其变为 (a + b) + (c + d),从而同时计算部分和。

Broader loop-vectorization is often enabled by using these algebraic methods as well. These methods are non-deterministic, since the compiler is free to choose different optimizations, but they never cause undefined behavior. See the library documentation and the original API change proposal for more details. 使用这些代数方法通常也能启用更广泛的循环向量化。这些方法是非确定性的,因为编译器可以自由选择不同的优化方式,但它们绝不会导致未定义行为。更多详情请参阅标准库文档及原始 API 变更提案。

Buffered integer formatting

缓冲整数格式化

All of the primitive integer types now have a format_into method that takes a &mut NumBuffer<Self> parameter, which is a buffer that is large enough to hold the decimal format of any value of that type. The buffer itself is opaque, but the method returns the formatted &str with a lifetime borrowed from that buffer. 所有原始整数类型现在都有一个 format_into 方法,该方法接收一个 &mut NumBuffer<Self> 参数,这是一个足以容纳该类型任何值的十进制格式的缓冲区。缓冲区本身是不透明的,但该方法会返回一个从该缓冲区借用生命周期的格式化后的 &str

This method also bypasses much of the dynamic dispatch that you would get with buffered write! formatting, which can be a boon to performance. The itoa-benchmark repo now shows that format_into performs similarly to itoa 本身, so this could serve as a standard replacement for that dependency and others like it. 该方法还绕过了使用缓冲 write! 格式化时会产生的大量动态分发,这对性能大有裨益。itoa-benchmark 仓库显示 format_into 的性能与 itoa 库相当,因此它可以作为该依赖项及类似依赖项的标准替代方案。

Fix interaction between ManuallyDrop and Box

修复 ManuallyDrop 与 Box 之间的交互问题

Prior to Rust 1.96.0, there was a bug in the Rust compiler, which made the following code undefined behavior: 在 Rust 1.96.0 之前,Rust 编译器中存在一个 Bug,导致以下代码会产生未定义行为:

let mut x = ManuallyDrop::new(Box::new(1));
unsafe { ManuallyDrop::drop(&mut x) };
let x = x; // UB!

This is because the compiler considers it undefined behavior to move a Box that has been dropped (deallocated), and ManuallyDrop used to propagate that, such that moving ManuallyDrop<Box<_>> where the box has been dropped would also be considered UB. In Rust 1.96.0 we fixed this, so this code was no longer UB. In this release we have updated the ManuallyDrop documentation, providing a stable guarantee that this code will continue to not be UB in the future. See ManuallyDrop docs and the related RFC 3336 for more information. 这是因为编译器认为移动一个已被丢弃(释放)的 Box 是未定义行为,而 ManuallyDrop 过去会传播这种行为,导致移动一个已丢弃内部 BoxManuallyDrop<Box<_>> 也会被视为未定义行为。我们在 Rust 1.96.0 中修复了此问题,因此该代码不再是未定义行为。在此版本中,我们更新了 ManuallyDrop 的文档,提供了一个稳定的保证,即该代码在未来将继续保持非未定义行为。更多信息请参阅 ManuallyDrop 文档及相关的 RFC 3336。

Stabilized APIs

已稳定化的 API

  • str::substr_range
  • [T]::subslice_range
  • core::fmt::NumBuffer
  • <{integer}>::format_into
  • Send/Sync for std::process::CommandArgs
  • {fN}::algebraic_add
  • {fN}::algebraic_sub
  • {fN}::algebraic_mul
  • {fN}::algebraic_div
  • {fN}::algebraic_rem
  • NonZero<{integer}>::from_str_radix
  • String::from_utf16le
  • String::from_utf16le_lossy
  • String::from_utf16be
  • String::from_utf16be_lossy
  • [T]::strip_circumfix
  • str::strip_circumfix
  • Atomic<T>::from_mut
  • Atomic<T>::get_mut_slice
  • Atomic<T>::from_mut_slice
  • std::range::legacy

Other changes

其他变更

Check out everything that changed in Rust, Cargo, and Clippy. 查看 Rust、Cargo 和 Clippy 中发生的所有变更。

Contributors to 1.98.0

1.98.0 的贡献者

Many people came together to create Rust 1.98.0. We couldn’t have done it without all of you. Thanks! 许多人共同努力创造了 Rust 1.98.0。没有你们,我们无法做到这一点。谢谢!