Rust 1.91.0 穩定版已正式發佈,主要帶來以下變化:
aarch64-pc-windows-msvc現在是 Tier 1 平台
Rust 編譯器支持多種目標平台,但 Rust 團隊無法為所有平台提供同等程度的支持。為了清晰地標明每個目標平台的支持程度,使用了分級系統:
- Tier 3 targets 在技術上得到編譯器支持,但官方不檢查其代碼是否能夠構建或通過測試,也不在發佈版本中提供任何預構建的二進制文件。
- Tier 2 targets 保證能夠構建,並且提供預構建的二進制文件,但官方不會在這些平台上執行測試套件:生成的二進制文件可能無法工作或存在錯誤。
- Tier 1 targets 提供最高級別的支持保障,對於編譯器中合併的每一項更改,都會在這些平台上運行完整的測試套件。此外,還提供預編譯的二進制文件。
Rust 1.91.0 將aarch64-pc-windows-msvctarget 提升至 Tier 1 支持級別,為運行 Windows 的 64 位 ARM 系統用户提供最高級別的保障。
添加針對局部變量中懸空原始指針的 lint 規則
雖然 Rust 的借用檢查可以防止返回懸空引用,但它不會跟蹤原始指針。在此版本中,添加了一個默認警告的 lint,用於檢查函數返回的指向局部變量的原始指針。例如,類似這樣的代碼:
fn f() -> *const u8 {
let x = 0;
&x
}
現在將生成一個 lint:
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
值得注意的是,上面的代碼本身並不危險,因為它沒有執行任何危險操作。只有在函數返回後解引用原始指針才是不安全的。“我們期望 Rust 的未來版本能夠添加更多功能,幫助開發者安全地處理原始指針,以及更廣泛意義上的不安全代碼。”
平台支持
- 將 aarch64-pc-windows-msvc 提升至 Tier 1 支持
- 將 aarch64-pc-windows-gnullvm 和 x86_64-pc-windows-gnullvm 提升至 Tier 2 支持,並提供 host tools。注意:llvm-tools 和 MSI 安裝程序目前缺失,將在未來版本中添加。
更多詳情可查看:https://blog.rust-lang.org/2025/10/30/Rust-1.91.0/