Rust 1.69

最後更新


Rust 1.69 發布於 2023-04-20,目前最新修補版為 1.69.0,已停止支援,請升級到 1.100.1。

版本介紹


Rust 1.69 沒有大型新功能,但累積了超過 500 位貢獻者的 3,000 多個 commit。最明顯的變化在 Cargo:編譯警告可以自動修正時,會直接提示執行 cargo fix 或 cargo clippy --fix;建置腳本(build script)預設不再產生除錯資訊,加快編譯。升級要注意:對 packed 結構欄位取未對齊的參考,從警告正式變成硬性錯誤。

語言變更


  • 在 packed 結構上 derive 內建特徵時,Copy 欄位可以正常運作。
  • 關聯型別可以作為 union 的欄位。
  • x86 與 x86_64 的 cmpxchg16b target feature 穩定。

標準庫重點


  • CStr::from_bytes_until_nul 與 core::ffi::FromBytesUntilNulError 穩定,從含有結尾 NUL 的緩衝區取出 C 字串,詳見 std::ffi。
  • SocketAddr::new、ip、port 等方法可在 const 環境使用,詳見 std::net。
  • Rc 實作 AsFd 與 AsRawFd。

Cargo 與工具


  • 偵測到可自動修正的警告時,Cargo 會提示對應的 cargo fix --bin "名稱" 指令,詳見 開發工具。
  • 對函式庫 crate 執行 cargo install 時,會建議改用 cargo add。
  • 建置相依(含建置腳本)預設不產生除錯資訊;需要除錯時在 [profile.dev.build-override] 設 debug = true,見 Cargo。
  • 範例(example)型的執行檔也會設定 CARGO_BIN_NAME 環境變數。
  • rustdoc 搜尋字串以 ! 結尾時會搜尋巨集。

相容性注意


  • 對 packed 欄位取未對齊參考成為硬性錯誤(1.53 起警告、1.62 起預設拒絕),unsafe 見 unsafe。
  • rustup 的 rust-analysis 元件只剩警告用的佔位內容,-Zsave-analysis 已移除。
  • registry token 含無效字元時 Cargo 會報錯;[env] 設定表不得設定 CARGO_HOME。

CStr::from_bytes_until_nul:從緩衝區讀 C 字串


C 函式常把字串寫進固定長度的緩衝區,字串後面接一個 \0,再後面是無意義的殘留資料。CStr::from_bytes_until_nul 找到第一個 \0 就停,回傳到那裡為止的 &CStr;整段都沒有 \0 時回傳錯誤。相比之下,舊的 from_bytes_with_nul 要求 \0 剛好在最後一個位元組,FFI 的整體觀念見 FFI。
範例:
  1. use std::ffi::CStr;
  2. fn main() {
  3. let buf: [u8; 16] = *b"hello\0garbage!!!";
  4. let s = CStr::from_bytes_until_nul(&buf).unwrap();
  5. println!("{:?} {}", s, s.to_bytes().len());
  6. let no_nul = b"no terminator";
  7. println!("{:?}", CStr::from_bytes_until_nul(no_nul).is_err());
  8. }

輸出:
  1. "hello" 5
  2. true

本版新增的棄用 API


本版沒有新增棄用 API。

修補版本


本版沒有修補版本。

已知漏洞


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

仍影響 1.69.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
CVE-2024-43402stdstd::process::Command batch files argument escaping could be bypassed with trailing whitespace or periods早於 1.81.01.81.0
CVE-2024-24576stdstd::process::Command did not properly escape arguments of batch files on Windows早於 1.77.21.77.2
CVE-2023-40030cargoMalicious dependencies can inject arbitrary JavaScript into cargo-generated timing reports1.60.0 起,早於 1.72.01.72.0
CVE-2023-38497cargoCargo not respecting umask when extracting crate archives早於 1.71.11.71.1

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

資料來源