编程 Rust 1.99.0:C 变参函数可由 Rust 定义,Box::leak 文档改口

2026-10-05 21:02:01

Rust 1.99.0:C 变参函数可由 Rust 定义,Box::leak 文档改口

Rust 1.99.0 于 2026-10-01 发布,分支自 2026-08-14。升级方式:

rustup update stable

下一个版本 Rust 1.100.0 计划 2026-11-12。发布公告:Rust 1.99.0,changelog:1.99.0。

语言与编译器稳定项

  • 稳定 C-variadic 函数定义:现在可以用 Rust 定义 extern "C" / "C-unwind" 变参函数,用 VaList(...)与 C va_list ABI 兼容,取参由 VaArgSafe 约束。此前 Rust 只能调用外部变参,不能实现。
  • #[unsafe(naked)] 函数可用于定义 C-variadic 函数:对应 feature #![feature(c_variadic_naked_functions)] 稳定。
  • 稳定 #[my_macro] mod foo;:在自定义属性宏或 derive 宏体内任意位置书写 outlined 模块(mod foo;)。
  • x86 上用 asm! 通过向量寄存器传 128 位整数。

行为变化:RangeInclusive

RangeInclusive(a..=b)迭代在某些情况下被更好地优化。副作用是,已耗尽作为迭代器的 RangeInclusive 的 start()/end() 返回值可能不同,用作 slice 索引行为也可能不同。这些行为本来没有稳定保证,所以不算 breaking change。

稳定新增 API

  • IntoIterator for Box<[T;N]> 及 &Box<[T;N]> / &mut Box<[T;N]>
  • VecDeque::retain_back
  • core::ffi::VaList
  • Box::into_non_null / Box::from_non_null
  • Vec::into_parts / Vec::from_parts
  • core::mem::size_of_val_raw、align_of_val_raw、core::alloc::Layout::for_value_raw
  • String::from_utf8_lossy_owned
  • string::FromUtf8Error::into_utf8_lossy
  • FusedIterator for StepBy
  • std::fs::set_times / set_times_nofollow

迁移注意

Box::leak 的文档现在建议不要事后 un-leak 该内存(优化器和自定义分配器交互),需要恢复所有权请优先 Box::into_non_null 或 Box::into_raw。

新增 allow-by-default lint raw_borrows_via_references,检查立即 decay 成裸引用的引用。

项目信息

  • 发布公告:https://blog.rust-lang.org/2026/10/01/Rust-1.99.0/
  • changelog:https://releases.rs/docs/1.99.0/
复制全文 生成海报 Rust 编程语言 版本发布

推荐文章

程序员茄子在线接单