# 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`，詳見[數值型別](/pkg-num)。
- `CStr`、`CString`、`Cow<CStr>` 之間可以直接用 `==` 比較，詳見 [std::ffi](/pkg-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 時也會一起驗證，詳見[工作區](/modules-workspaces)；發布仍不是原子操作，網路錯誤可能造成部分發布。
- 新增 `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](/pkg-env)。
- 依賴 SIGPIPE 結束程式的 socket 程式，要改成在寫入錯誤時自行結束。
- `core::iter::Fuse` 的 `Default` 改為依文件內部建立 `I::default()`。

### 無號整數減去有號數

當庫存是 `u8`、變化量是可正可負的 `i8` 時，以前得先轉型或分正負處理。新的 `*_sub_signed` 系列直接做「無號 − 有號」：`checked` 結果超出範圍回傳 `None`，`saturating` 夾在 0 與最大值之間，`wrapping` 繞回，`overflowing` 同時告訴你有沒有溢位。

範例：

```rust
fn main() {
    let stock: u8 = 10;
    for delta in [3i8, -4, 20] {
        println!(
            "{stock} - ({delta}) -> checked {:?}，saturating {}，wrapping {}",
            stock.checked_sub_signed(delta),
            stock.saturating_sub_signed(delta),
            stock.wrapping_sub_signed(delta),
        );
    }
    let (value, overflowed) = 250u8.overflowing_sub_signed(-10);
    println!("250 - (-10) -> {value}，溢位 {overflowed}");
}
```

輸出：

```text
10 - (3) -> checked Some(7)，saturating 7，wrapping 7
10 - (-4) -> checked Some(14)，saturating 14，wrapping 14
10 - (20) -> checked None，saturating 0，wrapping 246
250 - (-10) -> 4，溢位 true
```

### CStr 與 CString 互相比較

`CString` 是擁有所有權的 C 字串、`CStr` 是借用的 C 字串（`c"..."` 字面值的型別是 `&CStr`），概念類似 `String` 與 `&str`。現在兩者與 `Cow<CStr>` 之間都能直接用 `==` 比較內容，不必先轉成同一種型別。

範例：

```rust
use std::borrow::Cow;
use std::ffi::{CStr, CString};

fn main() {
    let owned = CString::new("hello").unwrap();
    let borrowed: &CStr = c"hello";
    let cow: Cow<CStr> = Cow::Borrowed(c"world");

    println!("{}", owned == *borrowed);
    println!("{}", *borrowed == owned);
    println!("{}", cow == *c"world");
    println!("{}", owned == cow);
}
```

輸出：

```text
true
true
true
false
```

## 本版新增的棄用 API

本版沒有新增棄用 API。

## 修補版本

本版沒有修補版本。

## 已知漏洞

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

### 仍影響 `1.90.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) |

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

## 資料來源

- [Rust 1.90 Release Notes](https://doc.rust-lang.org/stable/releases.html#version-1900-2025-09-18)
- [Rust 1.90 發布公告](https://blog.rust-lang.org/releases/1.90.0/)
- [rust-lang/rust 原始碼 1.90.0](https://github.com/rust-lang/rust/tree/1.90.0)
