Rust 1.90

最後更新


Rust 1.90 發布於 2025-09-18,目前最新修補版為 1.90.0,已停止支援,請升級到 1.100.1。

版本介紹


Rust 1.90 在 x86_64-unknown-linux-gnu 上改用 LLD 當預設連結器,大型程式、帶大量除錯資訊的程式與增量重建的連結時間都會縮短,多數專案不需要改任何東西。Cargo 也原生支援 cargo publish --workspace,依相依順序一次發布整個工作區。升級時要注意:若在 Linux 遇到新的連結問題,可以用 -C linker-features=-lld 退回原本的連結器;x86_64-apple-darwin(Intel Mac)從這版起降為 Tier 2 with host tools。

語言變更


  • unknown_or_malformed_diagnostic_attributes lint 拆成四個更細的 lint,原名改為包含它們的 lint 群組。
  • 允許最終值含有指向可變或外部記憶體的常數,但這類常數不能當模式使用。
  • 允許對非 Rust 管理的記憶體(包含位址 0)做 volatile 存取。

標準庫重點


  • 無號整數新增 checked_sub_signed、overflowing_sub_signed、saturating_sub_signed、wrapping_sub_signed,詳見數值型別。
  • CStr、CString、Cow<CStr> 之間可以直接用 == 比較,詳見 std::ffi。
  • IntErrorKind 實作 Copy 與 Hash。
  • f32/f64 的 floor、ceil、trunc、fract、round、round_ties_even 與 <[T]>::reverse 可在 const 情境使用。
  • Unix 上的 UnixStream 設定 MSG_NOSIGNAL,寫入已關閉的連線會回傳錯誤,而不是收到 SIGPIPE 訊號。

Cargo 與工具


  • 穩定多套件發布:cargo publish --workspace 依相依順序發布所有成員,dry-run 時也會一起驗證,詳見工作區;發布仍不是原子操作,網路錯誤可能造成部分發布。
  • 新增 http.proxy-cainfo 設定,指定代理伺服器的憑證。
  • rustdoc 可按住 Shift 一次收合所有 impl 區塊。

相容性注意


  • x86_64-unknown-linux-gnu 預設使用 LLD,遇到問題可在 RUSTFLAGS 或 .cargo/config.toml 加上 -Clinker-features=-lld。
  • Unix 上 HOME 環境變數為空字串時,std::env::home_dir 改走備援方式,詳見 std::env。
  • 依賴 SIGPIPE 結束程式的 socket 程式,要改成在寫入錯誤時自行結束。
  • core::iter::Fuse 的 Default 改為依文件內部建立 I::default()。

無號整數減去有號數


當庫存是 u8、變化量是可正可負的 i8 時,以前得先轉型或分正負處理。新的 *_sub_signed 系列直接做「無號 − 有號」:checked 結果超出範圍回傳 None,saturating 夾在 0 與最大值之間,wrapping 繞回,overflowing 同時告訴你有沒有溢位。
範例:
  1. fn main() {
  2. let stock: u8 = 10;
  3. for delta in [3i8, -4, 20] {
  4. println!(
  5. "{stock} - ({delta}) -> checked {:?},saturating {},wrapping {}",
  6. stock.checked_sub_signed(delta),
  7. stock.saturating_sub_signed(delta),
  8. stock.wrapping_sub_signed(delta),
  9. );
  10. }
  11. let (value, overflowed) = 250u8.overflowing_sub_signed(-10);
  12. println!("250 - (-10) -> {value},溢位 {overflowed}");
  13. }

輸出:
  1. 10 - (3) -> checked Some(7),saturating 7,wrapping 7
  2. 10 - (-4) -> checked Some(14),saturating 14,wrapping 14
  3. 10 - (20) -> checked None,saturating 0,wrapping 246
  4. 250 - (-10) -> 4,溢位 true

CStr 與 CString 互相比較


CString 是擁有所有權的 C 字串、CStr 是借用的 C 字串(c"..." 字面值的型別是 &CStr),概念類似 String 與 &str。現在兩者與 Cow<CStr> 之間都能直接用 == 比較內容,不必先轉成同一種型別。
範例:
  1. use std::borrow::Cow;
  2. use std::ffi::{CStr, CString};
  3. fn main() {
  4. let owned = CString::new("hello").unwrap();
  5. let borrowed: &CStr = c"hello";
  6. let cow: Cow<CStr> = Cow::Borrowed(c"world");
  7. println!("{}", owned == *borrowed);
  8. println!("{}", *borrowed == owned);
  9. println!("{}", cow == *c"world");
  10. println!("{}", owned == cow);
  11. }

輸出:
  1. true
  2. true
  3. true
  4. false

本版新增的棄用 API


本版沒有新增棄用 API。

修補版本


本版沒有修補版本。

已知漏洞


影響 1.90.0 的已知漏洞共 2 個;在本版修正的共 0 個;仍影響最新修補版 1.90.0 的共 2 個。官方未公布影響範圍的漏洞只列在修正它的版本,不計入其他版本。

仍影響 1.90.0


編號元件摘要(官方原文)影響範圍修正於
CVE-2026-5222cargoCargo can be coerced to share credentials between registries早於 1.96.01.96.0
CVE-2026-5223cargoCrates in third party registries can override the cached source of other crates早於 1.96.01.96.0

本版已停止支援,不會再修正這些漏洞;請升級到 1.100.1。

資料來源