秋风携新锈,Rust 1.91.0 悄然绽放

秋风携新锈,Rust 1.91.0 悄然绽放

Photos provided by Unsplash OR Pexels

秋风携新锈,1.91.0 悄然绽放

秋风轻拂,代码之林再添新叶。Rust 团队欣然宣布,Rust 1.91.0 正式发布——这门赋能世人铸就可靠高效软件的编程语言,又迈出了坚实一步。

若您已通过 rustup 安装旧版,只需轻敲:

$ rustup update stable

即可拥抱新版。若尚未安装,可前往 Rust 官网 获取 rustup,并查阅 1.91.0 详细发布笔记

欲助 Rust 团队测试未来版本,不妨切换至 beta 通道(rustup default beta)或 nightly 通道(rustup default nightly),并 报告 任何发现的 bug。

1.91.0 稳定版亮点

aarch64-pc-windows-msvc 荣升 Tier 1 平台

Rust 编译器支持 众多目标平台,但支持力度因阶层而异:

  • Tier 3:编译器技术支持,但不检查构建或测试,无预编译二进制文件。
  • Tier 2:保证构建并提供预编译二进制,但不运行测试套件,二进制可能存在缺陷。
  • Tier 1:最高保障,每合并变更均运行全套测试,并提供预编译二进制。

Rust 1.91.0 将 aarch64-pc-windows-msvc 目标提升至 Tier 1,为 64 位 ARM Windows 用户带来最高级别保证。

新增对局部变量悬垂原始指针的默认警告 lint

Rust 的借用检查器可防止悬垂引用返回,但对原始指针无能为力。本版引入默认警告 lint,针对从函数返回指向局部变量的原始指针。例如:

fn f() -> *const u8 {
    let x = 0;
    &x
}

将触发警告:

warning: a dangling pointer will be produced because the local variable `x` will be dropped
 --> src/lib.rs:3:5
  |
1 | fn f() -> *const u8 {
  |           --------- return type of the function is `*const u8`
2 |     let x = 0;
  |         - `x` is part the function and will be dropped at the end of the function
3 |     &x
  |     ^^
  |
  = note: pointers do not have a lifetime; after returning, the `u8` will be deallocated
    at the end of the function because nothing is referencing it as far as the type system is
    concerned
  = note: `#[warn(dangling_pointers_from_locals)]` on by default

此代码本身并非 unsafe,仅在函数返回后解引用原始指针才属 unsafe。未来版本将进一步增强对原始指针及 unsafe 代码的安全交互支持。

稳定化 API

const 上下文中稳定化的原有 API

平台支持更新

详见 Rust 平台支持页面

其他变更

详览 RustCargoClippy 的完整变更。

致谢 1.91.0 贡献者

无数双手共同铸就 Rust 1.91.0,离不开每一位贡献者。感谢你们!

版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)