# Rust 1.99

Rust 1.99 發布於 2026-10-01，目前最新修補版為 `1.99.1`，**已停止支援**，請升級到 `1.100.1`。

## 版本介紹

Rust 1.99 穩定以 `"C"` 與 `"C-unwind"` ABI 在 Rust 中「定義」C 風格的可變參數函式：以前 Rust 只能呼叫外部的 `printf` 這類函式，現在可以自己寫一個，參數 `...` 的型別是與 C `va_list` 相容的 `VaList`。標準庫也釐清了從原始指標取得大小與對齊的安全條件，並新增 `String::from_utf8_lossy_owned` 等實用 API。升級時要注意：`std::i32::MAX` 這類舊的整數模組常數全面棄用，請改寫成 `i32::MAX`；`#[no_mangle]` 用在泛型項目上變成硬錯誤；在 CI 環境（有 `CI` 環境變數）下 Cargo 預設關閉增量編譯。

### 語言變更

- 穩定 C 風格可變參數函式的定義（`"C"`、`"C-unwind"` ABI），以及用 `#[unsafe(naked)]` 裸函式定義其他 ABI 的可變參數函式，詳見 [FFI](/lowlevel-ffi)。
- 穩定 `#[my_macro] mod foo;`：外部檔案模組可以出現在屬性巨集或 derive 巨集的輸入中，詳見[程序式巨集](/macros-procedural)。
- 保證 `UnsafeCell` 的內容可以不經 `get` 存取；新增預設關閉的 `raw_borrows_via_references` lint，詳見 [unsafe](/lowlevel-unsafe)。
- `unconditional_panic` lint 擴及 chunks／windows 大小為零的呼叫；`unreachable_cfg_select_predicates` 加入 `unused` lint 群組。
- 缺少方法時，編譯器的建議會優先採用完全相符的 doc alias。

### 標準庫重點

- `core::ffi::VaList`，詳見 [std::ffi](/pkg-ffi)。
- `String::from_utf8_lossy_owned` 與 `FromUtf8Error::into_utf8_lossy`，詳見 [String](/pkg-string)。
- `mem::size_of_val_raw`、`mem::align_of_val_raw`、`Layout::for_value_raw`，詳見 [std::mem](/pkg-mem)。
- `Vec::into_parts`、`Vec::from_parts`、`Box::into_non_null`、`Box::from_non_null`；`Box<[T; N]>` 實作 `IntoIterator`，詳見 [Box](/pkg-boxed)。
- `std::fs::set_times`、`set_times_nofollow` 設定檔案時間，詳見 [std::fs](/pkg-fs)。
- `LocalKey<Cell<T>>::update`、`VecDeque::retain_back`、`StepBy` 實作 `FusedIterator`。
- `core::fmt::NumBuffer` 也從 `std::fmt` 重新匯出；`RangeInclusive` 迭代最佳化，已耗盡範圍的 `start()`／`end()` 回傳值可能改變。
- `Box::leak` 的文件建議不要再把洩漏的記憶體轉回 `Box` 釋放，改用 `Box::into_non_null` 或 `Box::into_raw`。

### Cargo 與工具

- 新增內建 profile `debug`，目前與 `dev` 完全相同，為日後調整 `dev` 做準備，詳見 [Cargo](/modules-cargo)。
- 2024 edition 以上的工作區成員可以覆寫繼承相依的 `default-features`，詳見[工作區](/modules-workspaces)。
- 偵測到 `CI` 環境變數時，Cargo 預設關閉增量編譯。
- rustdoc 新增 `unused_footnote_definition` lint，trait impl 過濾平均快 20%。

### 相容性注意

- 舊的整數模組（如 `std::i32::MAX`）全面棄用，改用 `i32::MAX`，詳見[棄用 API](/deprecations)。
- `no_mangle_generic_items` 升級為硬錯誤。
- 來自其他 crate、展開結果以分號結尾的巨集也會觸發警告（`semicolon_in_expressions_from_non_local_macros`），請回報給巨集的提供者。
- 文件測試中沒有套用對象的屬性會報錯，詳見[文件測試](/testing-doc)。
- `Pin::new_unchecked` 的安全不變條件略有調整，詳見 [std::pin](/pkg-pin)。

### 用 Rust 定義 C 可變參數函式

函式參數最後寫 `mut args: ...`，就能接收任意數量的參數；`args` 的型別是 `VaList`，用 `next_arg::<型別>()` 依序讀出。函式必須是 `unsafe extern "C"`，因為呼叫端要保證實際傳入的參數個數與型別正確，編譯器無法檢查。範例以第一個參數告訴函式後面有幾個 `i32`。

範例：

```rust
unsafe extern "C" fn sum(count: i32, mut args: ...) -> i32 {
    let mut total = 0;
    for _ in 0..count {
        total += unsafe { args.next_arg::<i32>() };
    }
    total
}

fn main() {
    let a = unsafe { sum(3, 10i32, 20i32, 30i32) };
    let b = unsafe { sum(0) };
    println!("{a} {b}");
}
```

輸出：

```text
60 0
```

注意：讀取超過實際傳入個數的參數，或用錯型別讀取，都是未定義行為，詳見 [unsafe](/lowlevel-unsafe)。

### String::from_utf8_lossy_owned

`String::from_utf8_lossy` 回傳 `Cow<str>`，若想要 `String` 還得再呼叫 `into_owned()`。`from_utf8_lossy_owned` 直接接收 `Vec<u8>` 並回傳 `String`，不合法的位元組以 `�`（U+FFFD）取代。`from_utf8` 失敗時得到的 `FromUtf8Error` 也能用 `into_utf8_lossy` 轉成同樣修補過的 `String`。

範例：

```rust
fn main() {
    let bytes = vec![b'h', b'i', 0xFF, b'!'];
    let text: String = String::from_utf8_lossy_owned(bytes);
    println!("{text}");

    let bad = vec![0xE5, 0x8F, b'A'];
    match String::from_utf8(bad) {
        Ok(s) => println!("合法：{s}"),
        Err(e) => println!("修補後：{}", e.into_utf8_lossy()),
    }
}
```

輸出：

```text
hi�!
修補後：�A
```

## 本版新增的棄用 API

以下 API 從 Rust 1.99 起標記為棄用（deprecated），新程式不要再使用；說明欄為官方原文。

| 模組 | 項目 | 官方說明 |
| --- | --- | --- |
| `std` | [`i128::max_value`](https://doc.rust-lang.org/std/primitive.i128.html#method.max_value) | replaced by the MAX associated constant on this type |
| `std` | [`i128::min_value`](https://doc.rust-lang.org/std/primitive.i128.html#method.min_value) | replaced by the MIN associated constant on this type |
| `std` | [`i16::max_value`](https://doc.rust-lang.org/std/primitive.i16.html#method.max_value) | replaced by the MAX associated constant on this type |
| `std` | [`i16::min_value`](https://doc.rust-lang.org/std/primitive.i16.html#method.min_value) | replaced by the MIN associated constant on this type |
| `std` | [`i32::max_value`](https://doc.rust-lang.org/std/primitive.i32.html#method.max_value) | replaced by the MAX associated constant on this type |
| `std` | [`i32::min_value`](https://doc.rust-lang.org/std/primitive.i32.html#method.min_value) | replaced by the MIN associated constant on this type |
| `std` | [`i64::max_value`](https://doc.rust-lang.org/std/primitive.i64.html#method.max_value) | replaced by the MAX associated constant on this type |
| `std` | [`i64::min_value`](https://doc.rust-lang.org/std/primitive.i64.html#method.min_value) | replaced by the MIN associated constant on this type |
| `std` | [`i8::max_value`](https://doc.rust-lang.org/std/primitive.i8.html#method.max_value) | replaced by the MAX associated constant on this type |
| `std` | [`i8::min_value`](https://doc.rust-lang.org/std/primitive.i8.html#method.min_value) | replaced by the MIN associated constant on this type |
| `std` | [`isize::max_value`](https://doc.rust-lang.org/std/primitive.isize.html#method.max_value) | replaced by the MAX associated constant on this type |
| `std` | [`isize::min_value`](https://doc.rust-lang.org/std/primitive.isize.html#method.min_value) | replaced by the MIN associated constant on this type |
| `std` | [`u128::max_value`](https://doc.rust-lang.org/std/primitive.u128.html#method.max_value) | replaced by the MAX associated constant on this type |
| `std` | [`u128::min_value`](https://doc.rust-lang.org/std/primitive.u128.html#method.min_value) | replaced by the MIN associated constant on this type |
| `std` | [`u16::max_value`](https://doc.rust-lang.org/std/primitive.u16.html#method.max_value) | replaced by the MAX associated constant on this type |
| `std` | [`u16::min_value`](https://doc.rust-lang.org/std/primitive.u16.html#method.min_value) | replaced by the MIN associated constant on this type |
| `std` | [`u32::max_value`](https://doc.rust-lang.org/std/primitive.u32.html#method.max_value) | replaced by the MAX associated constant on this type |
| `std` | [`u32::min_value`](https://doc.rust-lang.org/std/primitive.u32.html#method.min_value) | replaced by the MIN associated constant on this type |
| `std` | [`u64::max_value`](https://doc.rust-lang.org/std/primitive.u64.html#method.max_value) | replaced by the MAX associated constant on this type |
| `std` | [`u64::min_value`](https://doc.rust-lang.org/std/primitive.u64.html#method.min_value) | replaced by the MIN associated constant on this type |
| `std` | [`u8::max_value`](https://doc.rust-lang.org/std/primitive.u8.html#method.max_value) | replaced by the MAX associated constant on this type |
| `std` | [`u8::min_value`](https://doc.rust-lang.org/std/primitive.u8.html#method.min_value) | replaced by the MIN associated constant on this type |
| `std` | [`usize::max_value`](https://doc.rust-lang.org/std/primitive.usize.html#method.max_value) | replaced by the MAX associated constant on this type |
| `std` | [`usize::min_value`](https://doc.rust-lang.org/std/primitive.usize.html#method.min_value) | replaced by the MIN associated constant on this type |
| `std::f32` | [`DIGITS`](https://doc.rust-lang.org/std/f32/constant.DIGITS.html) | replaced by the DIGITS associated constant on f32 |
| `std::f32` | [`EPSILON`](https://doc.rust-lang.org/std/f32/constant.EPSILON.html) | replaced by the EPSILON associated constant on f32 |
| `std::f32` | [`INFINITY`](https://doc.rust-lang.org/std/f32/constant.INFINITY.html) | replaced by the INFINITY associated constant on f32 |
| `std::f32` | [`MANTISSA_DIGITS`](https://doc.rust-lang.org/std/f32/constant.MANTISSA_DIGITS.html) | replaced by the MANTISSA_DIGITS associated constant on f32 |
| `std::f32` | [`MAX`](https://doc.rust-lang.org/std/f32/constant.MAX.html) | replaced by the MAX associated constant on f32 |
| `std::f32` | [`MAX_10_EXP`](https://doc.rust-lang.org/std/f32/constant.MAX_10_EXP.html) | replaced by the MAX_10_EXP associated constant on f32 |
| `std::f32` | [`MAX_EXP`](https://doc.rust-lang.org/std/f32/constant.MAX_EXP.html) | replaced by the MAX_EXP associated constant on f32 |
| `std::f32` | [`MIN`](https://doc.rust-lang.org/std/f32/constant.MIN.html) | replaced by the MIN associated constant on f32 |
| `std::f32` | [`MIN_10_EXP`](https://doc.rust-lang.org/std/f32/constant.MIN_10_EXP.html) | replaced by the MIN_10_EXP associated constant on f32 |
| `std::f32` | [`MIN_EXP`](https://doc.rust-lang.org/std/f32/constant.MIN_EXP.html) | replaced by the MIN_EXP associated constant on f32 |
| `std::f32` | [`MIN_POSITIVE`](https://doc.rust-lang.org/std/f32/constant.MIN_POSITIVE.html) | replaced by the MIN_POSITIVE associated constant on f32 |
| `std::f32` | [`NAN`](https://doc.rust-lang.org/std/f32/constant.NAN.html) | replaced by the NAN associated constant on f32 |
| `std::f32` | [`NEG_INFINITY`](https://doc.rust-lang.org/std/f32/constant.NEG_INFINITY.html) | replaced by the NEG_INFINITY associated constant on f32 |
| `std::f32` | [`RADIX`](https://doc.rust-lang.org/std/f32/constant.RADIX.html) | replaced by the RADIX associated constant on f32 |
| `std::f64` | [`DIGITS`](https://doc.rust-lang.org/std/f64/constant.DIGITS.html) | replaced by the DIGITS associated constant on f64 |
| `std::f64` | [`EPSILON`](https://doc.rust-lang.org/std/f64/constant.EPSILON.html) | replaced by the EPSILON associated constant on f64 |
| `std::f64` | [`INFINITY`](https://doc.rust-lang.org/std/f64/constant.INFINITY.html) | replaced by the INFINITY associated constant on f64 |
| `std::f64` | [`MANTISSA_DIGITS`](https://doc.rust-lang.org/std/f64/constant.MANTISSA_DIGITS.html) | replaced by the MANTISSA_DIGITS associated constant on f64 |
| `std::f64` | [`MAX`](https://doc.rust-lang.org/std/f64/constant.MAX.html) | replaced by the MAX associated constant on f64 |
| `std::f64` | [`MAX_10_EXP`](https://doc.rust-lang.org/std/f64/constant.MAX_10_EXP.html) | replaced by the MAX_10_EXP associated constant on f64 |
| `std::f64` | [`MAX_EXP`](https://doc.rust-lang.org/std/f64/constant.MAX_EXP.html) | replaced by the MAX_EXP associated constant on f64 |
| `std::f64` | [`MIN`](https://doc.rust-lang.org/std/f64/constant.MIN.html) | replaced by the MIN associated constant on f64 |
| `std::f64` | [`MIN_10_EXP`](https://doc.rust-lang.org/std/f64/constant.MIN_10_EXP.html) | replaced by the MIN_10_EXP associated constant on f64 |
| `std::f64` | [`MIN_EXP`](https://doc.rust-lang.org/std/f64/constant.MIN_EXP.html) | replaced by the MIN_EXP associated constant on f64 |
| `std::f64` | [`MIN_POSITIVE`](https://doc.rust-lang.org/std/f64/constant.MIN_POSITIVE.html) | replaced by the MIN_POSITIVE associated constant on f64 |
| `std::f64` | [`NAN`](https://doc.rust-lang.org/std/f64/constant.NAN.html) | replaced by the NAN associated constant on f64 |
| `std::f64` | [`NEG_INFINITY`](https://doc.rust-lang.org/std/f64/constant.NEG_INFINITY.html) | replaced by the NEG_INFINITY associated constant on f64 |
| `std::f64` | [`RADIX`](https://doc.rust-lang.org/std/f64/constant.RADIX.html) | replaced by the RADIX associated constant on f64 |
| `std::i128` | [`MAX`](https://doc.rust-lang.org/std/i128/constant.MAX.html) | replaced by the MAX associated constant on this type |
| `std::i128` | [`MIN`](https://doc.rust-lang.org/std/i128/constant.MIN.html) | replaced by the MIN associated constant on this type |
| `std::i16` | [`MAX`](https://doc.rust-lang.org/std/i16/constant.MAX.html) | replaced by the MAX associated constant on this type |
| `std::i16` | [`MIN`](https://doc.rust-lang.org/std/i16/constant.MIN.html) | replaced by the MIN associated constant on this type |
| `std::i32` | [`MAX`](https://doc.rust-lang.org/std/i32/constant.MAX.html) | replaced by the MAX associated constant on this type |
| `std::i32` | [`MIN`](https://doc.rust-lang.org/std/i32/constant.MIN.html) | replaced by the MIN associated constant on this type |
| `std::i64` | [`MAX`](https://doc.rust-lang.org/std/i64/constant.MAX.html) | replaced by the MAX associated constant on this type |
| `std::i64` | [`MIN`](https://doc.rust-lang.org/std/i64/constant.MIN.html) | replaced by the MIN associated constant on this type |
| `std::i8` | [`MAX`](https://doc.rust-lang.org/std/i8/constant.MAX.html) | replaced by the MAX associated constant on this type |
| `std::i8` | [`MIN`](https://doc.rust-lang.org/std/i8/constant.MIN.html) | replaced by the MIN associated constant on this type |
| `std::isize` | [`MAX`](https://doc.rust-lang.org/std/isize/constant.MAX.html) | replaced by the MAX associated constant on this type |
| `std::isize` | [`MIN`](https://doc.rust-lang.org/std/isize/constant.MIN.html) | replaced by the MIN associated constant on this type |
| `std::sync::atomic` | [`Atomic::fetch_update`](https://doc.rust-lang.org/std/sync/atomic/struct.Atomic.html#method.fetch_update) | renamed to try_update for consistency |
| `std::u128` | [`MAX`](https://doc.rust-lang.org/std/u128/constant.MAX.html) | replaced by the MAX associated constant on this type |
| `std::u128` | [`MIN`](https://doc.rust-lang.org/std/u128/constant.MIN.html) | replaced by the MIN associated constant on this type |
| `std::u16` | [`MAX`](https://doc.rust-lang.org/std/u16/constant.MAX.html) | replaced by the MAX associated constant on this type |
| `std::u16` | [`MIN`](https://doc.rust-lang.org/std/u16/constant.MIN.html) | replaced by the MIN associated constant on this type |
| `std::u32` | [`MAX`](https://doc.rust-lang.org/std/u32/constant.MAX.html) | replaced by the MAX associated constant on this type |
| `std::u32` | [`MIN`](https://doc.rust-lang.org/std/u32/constant.MIN.html) | replaced by the MIN associated constant on this type |
| `std::u64` | [`MAX`](https://doc.rust-lang.org/std/u64/constant.MAX.html) | replaced by the MAX associated constant on this type |
| `std::u64` | [`MIN`](https://doc.rust-lang.org/std/u64/constant.MIN.html) | replaced by the MIN associated constant on this type |
| `std::u8` | [`MAX`](https://doc.rust-lang.org/std/u8/constant.MAX.html) | replaced by the MAX associated constant on this type |
| `std::u8` | [`MIN`](https://doc.rust-lang.org/std/u8/constant.MIN.html) | replaced by the MIN associated constant on this type |
| `std::usize` | [`MAX`](https://doc.rust-lang.org/std/usize/constant.MAX.html) | replaced by the MAX associated constant on this type |
| `std::usize` | [`MIN`](https://doc.rust-lang.org/std/usize/constant.MIN.html) | replaced by the MIN associated constant on this type |

## 修補版本

| 版本 | 發布日期 | 含安全修補 | 內容（官方原文） |
| --- | --- | --- | --- |
| `1.99.1` | 2026-10-15 | 否 | library: fix missing symbol `wcslen` on UEFI and embedded targets；rustc: fix miscompilation of FFI `bool` return values on x86_64；rust-lld: add the rpath for `libLLVM` on macOS |

## 已知漏洞

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

## 資料來源

- [Rust 1.99 Release Notes](https://doc.rust-lang.org/stable/releases.html#version-1990-2026-10-01)
- [Rust 1.99 發布公告](https://blog.rust-lang.org/releases/1.99.0/)
- [rust-lang/rust 原始碼 1.99.0](https://github.com/rust-lang/rust/tree/1.99.0)
