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 的
cmpxchg16btarget 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。範例:
- use std::ffi::CStr;
- fn main() {
- let buf: [u8; 16] = *b"hello\0garbage!!!";
- let s = CStr::from_bytes_until_nul(&buf).unwrap();
- println!("{:?} {}", s, s.to_bytes().len());
- let no_nul = b"no terminator";
- println!("{:?}", CStr::from_bytes_until_nul(no_nul).is_err());
- }
輸出:
- "hello" 5
- true
本版新增的棄用 API
本版沒有新增棄用 API。
修補版本
本版沒有修補版本。
已知漏洞
影響
1.69.0 的已知漏洞共 6 個;在本版修正的共 0 個;仍影響最新修補版 1.69.0 的共 6 個。官方未公布影響範圍的漏洞只列在修正它的版本,不計入其他版本。仍影響 1.69.0
| 編號 | 元件 | 摘要(官方原文) | 影響範圍 | 修正於 |
|---|---|---|---|---|
| CVE-2026-5222 | cargo | Cargo can be coerced to share credentials between registries | 早於 1.96.0 | 1.96.0 |
| CVE-2026-5223 | cargo | Crates in third party registries can override the cached source of other crates | 早於 1.96.0 | 1.96.0 |
| CVE-2024-43402 | std | std::process::Command batch files argument escaping could be bypassed with trailing whitespace or periods | 早於 1.81.0 | 1.81.0 |
| CVE-2024-24576 | std | std::process::Command did not properly escape arguments of batch files on Windows | 早於 1.77.2 | 1.77.2 |
| CVE-2023-40030 | cargo | Malicious dependencies can inject arbitrary JavaScript into cargo-generated timing reports | 1.60.0 起,早於 1.72.0 | 1.72.0 |
| CVE-2023-38497 | cargo | Cargo not respecting umask when extracting crate archives | 早於 1.71.1 | 1.71.1 |
本版已停止支援,不會再修正這些漏洞;請升級到
1.100.1。