Rust 1.99.0 发布公告
摘要
Rust 团队宣布推出 Rust 1.99.0,稳定了 C-ABI 可变参数函数、基于原始指针的布局信息 API,并在自定义分配器支持到来之前更新了关于 Box::leak 用法的指导建议。
<p><a href="https://lobste.rs/s/dfvxvs/announcing_rust_1_99_0">评论</a></p>
查看缓存全文
缓存时间: 2026/10/01 14:26
# Rust 1.99.0 发布公告 | Rust Blog
来源:https://blog.rust-lang.org/2026/10/01/Rust-1.99.0/
Rust 团队很高兴地宣布 Rust 的新版本 1.99.0。Rust 是一门让每个人都能构建可靠、高效软件的编程语言。
如果你之前已通过 `rustup` 安装过 Rust,可以使用以下命令升级到 1.99.0:
```
$ rustup update stable
```
如果还没有安装,可以前往官网对应页面获取 `rustup`(https://www.rust-lang.org/install.html),并查阅 1.99.0 的[详细发布说明](https://doc.rust-lang.org/stable/releases.html#version-1990-2026-10-01)。
如果你想通过测试未来的版本为我们提供帮助,可以考虑在本地切换到 beta 渠道(`rustup default beta`)或 nightly 渠道(`rustup default nightly`)。如果遇到任何 bug,请[进行报告](https://github.com/rust-lang/rust/issues/new/choose)!
## 1.99.0 stable 中有什么
### extern "C" 可变参数
Rust 1.99.0 稳定了对使用 "C" 和 "C-unwind" ABI 定义 C-ABI 可变参数函数的支持。这样定义的可变参数函数使用可变参数列表(`...`),可以接受任意数量的参数。
此前 Rust 已经可以调用外部定义的可变参数函数(例如 `libc::printf`)。而在 Rust 1.99 中,这些函数现在可以直接用 Rust 编写:
```rust
/// SAFETY: must be called with (at least) 2 i32 arguments.
unsafe extern "C" fn sum(mut args: ...) -> i32 {
// SAFETY: guaranteed by the caller.
let a = unsafe { args.next_arg::<i32>() };
let b = unsafe { args.next_arg::<i32>() };
a + b
}
fn foo() -> i32 {
unsafe { sum(0i32, 2i32) }
}
```
`...` 的类型是 [`VaList`](https://doc.rust-lang.org/std/ffi/struct.VaList.html),它在各目标平台上与 C 的 `va_list` 类型 ABI 兼容。可以从 `VaList` 中读取哪些类型由 [`VaArgSafe`](https://doc.rust-lang.org/std/ffi/trait.VaArgSafe.html) trait 约束。关于 c-variadic 函数的更多细节,请参阅[参考文档](https://doc.rust-lang.org/reference/items/functions.html#c-variadic-functions)。
本次发布还稳定了对使用非 "C" ABI 定义裸(naked)可变参数函数的支持,这类函数必须通过内联汇编编写。
### 从裸指针获取布局信息
本次发布明确了从指向 `Sized`(天然安全,stable 上已可行)和非 `Sized` 类型的裸指针上获取大小与对齐方式的安全要求。具体做法是稳定了以下三个函数:
- [`Layout::for_value_raw`](https://doc.rust-lang.org/stable/core/alloc/struct.Layout.html#method.for_value_raw)
- [`mem::size_of_val_raw`](https://doc.rust-lang.org/stable/core/mem/fn.size_of_val_raw.html)
- [`mem::align_of_val_raw`](https://doc.rust-lang.org/stable/core/mem/fn.align_of_val_raw.html)
### 不推荐在 `Box::leak` 之后进行"反泄漏"操作
虽然 Rust 1.99 没有对语言语义做任何改动,但我们更新了 [`Box::leak`](https://doc.rust-lang.org/std/boxed/struct.Box.html#method.leak) 的文档,不建议再使用之后释放该内存的模式。
之所以这样更新,是因为此类代码被发现与当前及未来可能的编译器优化存在冲突的交互,而且在即将稳定化的自定义分配器中问题尤其突出。因此,应优先使用 [`Box::into_non_null`](https://doc.rust-lang.org/std/boxed/struct.Box.html#method.into_non_null)。
这一指引同样适用于标准库中的其他 `leak` 函数。
### 稳定的 API
- [`IntoIterator` for `Box<[T; N]>`](https://doc.rust-lang.org/stable/std/iter/trait.IntoIterator.html#impl-IntoIterator-for-Box%3C%5BT;+N%5D,+A%3E)
- [`IntoIterator` for `&Box<[T; N]>`](https://doc.rust-lang.org/stable/std/iter/trait.IntoIterator.html#impl-IntoIterator-for-%26Box%3C%5BT;+N%5D,+A%3E)
- [`IntoIterator` for `&mut Box<[T; N]>`](https://doc.rust-lang.org/stable/std/iter/trait.IntoIterator.html#impl-IntoIterator-for-%26mut+Box%3C%5BT;+N%5D,+A%3E)
- [`VecDeque::retain_back`](https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.retain_back)
- [`core::ffi::VaList`](https://doc.rust-lang.org/stable/core/ffi/struct.VaList.html)
- [`Box::into_non_null`](https://doc.rust-lang.org/stable/std/boxed/struct.Box.html#method.into_non_null)
- [`Box::from_non_null`](https://doc.rust-lang.org/stable/std/boxed/struct.Box.html#method.from_non_null)
- [`Vec::into_parts`](https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.into_parts)
- [`Vec::from_parts`](https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.from_parts)
- [`core::mem::size_of_val_raw`](https://doc.rust-lang.org/stable/core/mem/fn.size_of_val_raw.html)
- [`core::mem::align_of_val_raw`](https://doc.rust-lang.org/stable/core/mem/fn.align_of_val_raw.html)
- [`core::alloc::Layout::for_value_raw`](https://doc.rust-lang.org/stable/core/alloc/struct.Layout.html#method.for_value_raw)
- [`String::from_utf8_lossy_owned`](https://doc.rust-lang.org/stable/std/string/struct.String.html#method.from_utf8_lossy_owned)
- [`string::FromUtf8Error::into_utf8_lossy`](https://doc.rust-lang.org/stable/std/string/struct.FromUtf8Error.html#method.into_utf8_lossy)
- [`FusedIterator` for `StepBy`](https://doc.rust-lang.org/stable/std/iter/struct.StepBy.html#impl-FusedIterator-for-StepBy%3CI%3E)
- [`std::fs::set_times`](https://doc.rust-lang.org/stable/std/fs/fn.set_times.html)
- [`std::fs::set_times_nofollow`](https://doc.rust-lang.org/stable/std/fs/fn.set_times_nofollow.html)
### 其他变更
请查看 [Rust](https://github.com/rust-lang/rust/releases/tag/1.99.0)、[Cargo](https://doc.rust-lang.org/nightly/cargo/CHANGELOG.html#cargo-199-2026-10-01) 和 [Clippy](https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-199) 中的所有变更内容。
## 1.99.0 的贡献者
许多人共同努力完成了 Rust 1.99.0。没有你们所有人,我们无法做到这一切。谢谢!(https://thanks.rust-lang.org/rust/1.99.0/)
相似文章
Rust 1.98.0 发布
Rust 1.98.0 发布,引入代数浮点方法以优化操作,缓冲整数格式化以提高性能,并修复了 ManuallyDrop 和 Box 之间的交互问题。
Rust 1.97.0 发布公告
Rust 1.97.0 已发布,默认启用符号修饰 v0,Cargo 支持禁止警告,并且链接器输出不再隐藏。
Rust 1.98.1 发布
Rust 1.98.1 是一个补丁版本,修复了 vtable 生成中的一个错误编译漏洞,该漏洞可能导致编译后的代码出现未定义行为。
宣布发布 Rust 1.99.1
Rust 1.99.1 发布,这是一个修复性点版本,解决了 wcslen 符号缺失、x86_64 上 FFI bool 返回值误编译以及 macOS 上 rustlld 无法加载 libLLVM 三项回归问题。
2026年分配器的现状 - 六个月后
本文更新了Rust中自定义分配器的稳定化进展,重点介绍了最近的开发,例如Allocator trait变得dyn兼容,以及解决不健全性问题的努力。