# Rust 1.84

Rust 1.84 發布於 2025-01-09，目前最新修補版為 `1.84.1`，**已停止支援**，請升級到 `1.100.1`。

## 版本介紹

Rust 1.84 讓 Cargo 在挑選相依版本時考慮專案宣告的最低支援 Rust 版本（MSRV），舊工具鏈的使用者不必再手動挑舊版相依。編譯器也開始遷移到新一代特徵求解器（trait solver），本版先用在 impl 的一致性（coherence）檢查；標準庫則新增嚴格來源（strict provenance）指標 API 與整數平方根 `isqrt`。升級時要注意：`wasm32-wasi` 目標已移除，請改用 `wasm32-wasip1`；新求解器可能回報少數以前沒抓到的「conflicting implementations」錯誤。

### 語言變更

- 特徵 impl 的一致性檢查改用新一代特徵求解器，修正數個理論上的正確性問題，詳見 [特徵進階](/traits-advanced)。
- 對指標解參考取原始參考（`&raw const *ptr`）不再需要 `unsafe`，詳見 [unsafe](/lowlevel-unsafe)。
- 新增 lint，警告建立指向立即被丟棄之暫存值的指標。
- `extern "C"` 函式在展開（unwinding）時會執行 drop。
- 在 `#[forbid]` 內使用 `#[deny]` 視為無作用，不再報錯。

### 標準庫重點

- 新增嚴格來源 API：`ptr::addr`、`with_addr`、`map_addr`、`expose_provenance`、`ptr::without_provenance`、`ptr::dangling` 等，詳見 [std::ptr](/pkg-ptr)。
- 整數新增 `isqrt` 與 `checked_isqrt`，詳見 [std::num](/pkg-num)。
- `Ipv6Addr` 新增 `is_unique_local` 與 `is_unicast_link_local`，詳見 [std::net](/pkg-net)。
- 新增 `Pin::as_deref_mut`，詳見 [std::pin](/pkg-pin)。
- `CString` 實作 `FromStr`，`String` 實作 `TryFrom<CString>`，詳見 [std::ffi](/pkg-ffi)。

### Cargo 與工具

- 穩定 MSRV 感知的解析器設定與 resolver v3：在 `.cargo/config.toml` 設定 `[resolver]` 的 `incompatible-rust-versions = "fallback"`，或在 `Cargo.toml` 設 `package.resolver = "3"`（需要 MSRV 1.84），詳見 [Cargo 與套件](/modules-cargo)。
- 2024 edition 的專案會預設啟用新解析器。
- `rustc` 新增 `--print host-tuple`，印出主機的目標組合（target tuple）。

### 相容性注意

- 移除 `wasm32-wasi` 目標，改名為 `wasm32-wasip1`。
- 宣告目前目標不支援的呼叫慣例會變成硬錯誤。
- 移除不穩定的 `-Zprofile` 旗標；穩定的 `-Cinstrument-coverage` 與 PGO 旗標不受影響。
- `&pin (mut|const) T` 會被解析成型別，少數巨集展開結果可能改變。

### 整數平方根 isqrt

`isqrt` 回傳整數平方根，也就是不超過真正平方根的最大整數，例如 `10.isqrt()` 是 `3`。有號整數對負數呼叫 `isqrt` 會 panic，需要安全處理時用 `checked_isqrt`，負數會得到 `None`。

範例：

```rust
fn main() {
    println!("{}", 10u32.isqrt());
    println!("{}", 99u64.isqrt());
    println!("{:?}", 16i32.checked_isqrt());
    println!("{:?}", (-4i32).checked_isqrt());

    let area = 1_000_000u64;
    let side = area.isqrt();
    println!("{side} x {side} = {}", side * side);
}
```

輸出：

```text
3
9
Some(4)
None
1000 x 1000 = 1000000
```

### Ipv6Addr 的位址分類

`is_unique_local` 判斷是否為 `fc00::/7` 的唯一本地位址（類似 IPv4 的私有網段），`is_unicast_link_local` 判斷是否為 `fe80::/10` 的鏈路本地位址。寫網路程式時可以用來過濾不該對外連線的位址。

範例：

```rust
use std::net::Ipv6Addr;

fn main() {
    let addrs: [Ipv6Addr; 3] = [
        "fd00::1".parse().unwrap(),
        "fe80::1".parse().unwrap(),
        "2001:db8::1".parse().unwrap(),
    ];
    for a in addrs {
        println!("{a}: unique_local={} link_local={}", a.is_unique_local(), a.is_unicast_link_local());
    }
}
```

輸出：

```text
fd00::1: unique_local=true link_local=false
fe80::1: unique_local=false link_local=true
2001:db8::1: unique_local=false link_local=false
```

## 本版新增的棄用 API

本版沒有新增棄用 API。

## 修補版本

| 版本 | 發布日期 | 含安全修補 | 內容（官方原文） |
| --- | --- | --- | --- |
| `1.84.1` | 2025-01-30 | 否 | Fix ICE 132920 in duplicate-crate diagnostics.；Fix errors for overlapping impls in incremental rebuilds.；Fix slow compilation related to the next-generation trait solver.；Fix debuginfo when LLVM's location discriminator value limit is exceeded.；Fixes for building Rust from source:；Only try to distribute `llvm-objcopy` if llvm tools are enabled.；Add Profile Override for Non-Git Sources.；Resolve symlinks of LLVM tool binaries before copying them.；Make it possible to use ci-rustc on tarball sources. |

## 已知漏洞

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

### 仍影響 `1.84.1`

| 編號 | 元件 | 摘要（官方原文） | 影響範圍 | 修正於 |
| --- | --- | --- | --- | --- |
| [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.84 Release Notes](https://doc.rust-lang.org/stable/releases.html#version-1840-2025-01-09)
- [Rust 1.84 發布公告](https://blog.rust-lang.org/releases/1.84.0/)
- [rust-lang/rust 原始碼 1.84.0](https://github.com/rust-lang/rust/tree/1.84.0)
