# 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](/pkg-ffi)。
- `SocketAddr::new`、`ip`、`port` 等方法可在 const 環境使用，詳見 [std::net](/pkg-net)。
- `Rc` 實作 `AsFd` 與 `AsRawFd`。

### Cargo 與工具

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

### 相容性注意

- 對 packed 欄位取未對齊參考成為硬性錯誤（1.53 起警告、1.62 起預設拒絕），unsafe 見 [unsafe](/lowlevel-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](/lowlevel-ffi)。

範例：

```rust
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());
}
```

輸出：

```text
"hello" 5
true
```

## 本版新增的棄用 API

本版沒有新增棄用 API。

## 修補版本

本版沒有修補版本。

## 已知漏洞

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

### 仍影響 `1.69.0`

| 編號 | 元件 | 摘要（官方原文） | 影響範圍 | 修正於 |
| --- | --- | --- | --- | --- |
| [CVE-2026-5222](https://github.com/rust-lang/cargo/security/advisories/GHSA-p688-r7jv-fm6f) | cargo | Cargo can be coerced to share credentials between registries | 早於 1.96.0 | [1.96.0](/rust-1-96) |
| [CVE-2026-5223](https://github.com/rust-lang/cargo/security/advisories/GHSA-jq42-7mfv-hm57) | cargo | Crates in third party registries can override the cached source of other crates | 早於 1.96.0 | [1.96.0](/rust-1-96) |
| [CVE-2024-43402](https://github.com/rust-lang/rust/security/advisories/GHSA-2xg3-7mm6-98jj) | std | `std::process::Command` batch files argument escaping could be bypassed with trailing whitespace or periods | 早於 1.81.0 | [1.81.0](/rust-1-81) |
| [CVE-2024-24576](https://github.com/rust-lang/rust/security/advisories/GHSA-q455-m56c-85mh) | std | `std::process::Command` did not properly escape arguments of batch files on Windows | 早於 1.77.2 | [1.77.2](/rust-1-77) |
| [CVE-2023-40030](https://github.com/rust-lang/cargo/security/advisories/GHSA-wrrj-h57r-vx9p) | cargo | Malicious dependencies can inject arbitrary JavaScript into cargo-generated timing reports | 1.60.0 起，早於 1.72.0 | [1.72.0](/rust-1-72) |
| [CVE-2023-38497](https://github.com/rust-lang/cargo/security/advisories/GHSA-j3xp-wfr4-hx87) | cargo | Cargo not respecting umask when extracting crate archives | 早於 1.71.1 | [1.71.1](/rust-1-71) |

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

## 資料來源

- [Rust 1.69 Release Notes](https://doc.rust-lang.org/stable/releases.html#version-1690-2023-04-20)
- [Rust 1.69 發布公告](https://blog.rust-lang.org/releases/1.69.0/)
- [rust-lang/rust 原始碼 1.69.0](https://github.com/rust-lang/rust/tree/1.69.0)
