# Rust 1.14

Rust 1.14 發布於 2016-12-22，目前最新修補版為 `1.14.0`，**已停止支援**，請升級到 `1.100.1`。

## 版本介紹

Rust 1.14 最大的消息不在語言本身：rustup 發布 1.0，成為官方建議的安裝方式，可以輕鬆切換 stable、beta、nightly 並加裝交叉編譯用的標準庫。這版也以實驗方式支援 WebAssembly 目標 `wasm32-unknown-emscripten`，並新增 MIPS、PowerPC、s390x 等主機平台。語言方面，`..` 可以在元組與元組結構的模式中略過任意數量的欄位。升級要注意：多個前向相容 lint 改為預設拒絕（deny），以前只是警告的程式碼現在會編譯失敗；rustup 預設不再安裝文件，需要時執行 `rustup component add rust-docs`。

### 語言變更

- `..` 可以在列舉變體、結構與元組的模式中比對多個元組欄位（RFC 1492），詳見 [模式](/control-patterns)。
- 安全的 `fn` 項目可以轉型成 `unsafe fn` 指標，詳見 [unsafe](/lowlevel-unsafe)。
- `use *` 與 `use ::*` 都從 crate 根部做 glob 匯入，詳見 [模組系統](/modules-system)。
- `Vec<Box<Fn()>>` 裡的閉包不必明確解參考就能呼叫，詳見 [閉包](/closures-basics)。

### 標準庫重點

- `println!()` 不帶任何引數時印出一個換行，詳見 [std::fmt](/pkg-fmt)。
- `String` 實作 `From<Cow<str>>`、`Vec<T>` 實作 `From<Cow<[T]>>`；`Cow<str>` 可以用 `+` 接上 `&str` 或 `Cow<str>`，詳見 [std::borrow](/pkg-borrow)。
- `Wrapping` 實作標準的二元與一元運算子，以及 `Sum`、`Product`，詳見 [std::num](/pkg-num)。
- `io::Error` 實作 `From<io::ErrorKind>`，詳見 [std::io](/pkg-io)。
- `HashMap` 的內部記憶體配置對快取更友善，部分操作明顯加快，也不再重複使用隨機種子，詳見 [HashMap](/pkg-collections-hash-map)。
- 原子型別實作 `RefUnwindSafe`；`ReadDir` 實作 `Debug`；`Vec::extend` 遇到切片時特化成 `extend_from_slice`。

### Cargo 與工具

- rustup 是官方建議的安裝方式，詳見 [安裝](/start-install)。
- 實驗性支援 WebAssembly：`rustup target add wasm32-unknown-emscripten` 後即可用 `rustc --target=wasm32-unknown-emscripten` 編譯，已知仍有重大缺陷。
- 新增 MIPS、PowerPC、s390x 的 Linux 主機建置，以及 ARM MUSL 的標準庫建置，都是 tier 2 平台。
- Cargo 把 `rustc --print cfg` 的值傳給建置腳本；`CARGO_HOME` 唯讀時也能運作；測試與 bench 設定檔忽略 `panic` 設定，避免 `panic=abort` 讓單一測試失敗中止整個測試套件，詳見 [Cargo](/modules-cargo)。
- Rust 發行版啟用行號除錯資訊；`rustc --version --verbose` 會顯示 LLVM 版本。

### 相容性注意

- 多個前向相容 lint 改為預設拒絕，例如浮點數常數不能用在模式中、結構或列舉常數必須 `#[derive(PartialEq, Eq)]` 才能用於模式。
- 原子型別的 `Ordering` 列舉不能再窮舉比對，詳見 [std::sync::atomic](/pkg-sync-atomic)。
- 沒有函式本體的特徵方法不能在參數使用模式；列舉不能是不定大小型別。
- 實作比特徵本身要求更多生命週期條件的 `impl` 會被拒絕。
- `$crate` 巨集變數可使用的位置變少，詳見 [宣告式巨集](/macros-declarative)。

### 模式中的 .. 略過部分欄位

以前元組結構只能用 `Point(..)` 一次略過全部欄位，想取第一個欄位就得把其他欄位都寫成 `_`。1.14 起 `..` 可以放在開頭、中間或結尾，只取需要的欄位，寫法和具名欄位結構的 `Point { x, .. }` 一致。

範例：

```rust
struct Rgb(u8, u8, u8);

enum Shape {
    Rect(u32, u32, &'static str),
}

fn main() {
    let c = Rgb(255, 128, 0);
    let Rgb(red, ..) = c;
    let Rgb(_, green, ..) = c;
    let Rgb(.., blue) = c;
    println!("red = {}, green = {}, blue = {}", red, green, blue);

    let t = (1, 2, 3, 4, 5);
    let (first, .., last) = t;
    println!("{} {}", first, last);

    let s = Shape::Rect(3, 4, "藍");
    match s {
        Shape::Rect(w, h, ..) => println!("面積 {}", w * h),
    }
    let Shape::Rect(.., color) = s;
    println!("顏色 {}", color);
}
```

輸出：

```text
red = 255, green = 128, blue = 0
1 5
面積 12
顏色 藍
```

注意：一個模式裡只能出現一次 `..`，寫成 `(a, .., b, .., c)` 會因為無法判斷略過哪些欄位而編譯失敗。

### println!() 與 Cow 轉換

`println!()` 不帶引數就印出空行，不必再寫 `println!("")`。`Cow<str>` 表示「可能借用、也可能擁有」的字串；1.14 起它能直接用 `into()` 或 `String::from` 轉成 `String`，也能用 `+` 接上字串切片。

範例：

```rust
use std::borrow::Cow;

fn normalize(input: &str) -> Cow<'_, str> {
    if input.contains(' ') {
        Cow::Owned(input.replace(' ', "_"))
    } else {
        Cow::Borrowed(input)
    }
}

fn main() {
    println!("第一行");
    println!();
    println!("空一行之後");

    let a: String = normalize("hello world").into();
    let b: String = String::from(normalize("rust"));
    println!("{} {}", a, b);

    let tail = Cow::Borrowed("abc") + "def";
    println!("{}", tail);
}
```

輸出：

```text
第一行

空一行之後
hello_world rust
abcdef
```

## 本版新增的棄用 API

本版沒有新增棄用 API。

## 修補版本

本版沒有修補版本。

## 已知漏洞

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

### 仍影響 `1.14.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-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) |
| [CVE-2022-46176](https://github.com/rust-lang/cargo/security/advisories/GHSA-r5w3-xm58-jv6j) | cargo | Cargo did not verify SSH host keys | 早於 1.66.1 | [1.66.1](/rust-1-66) |
| [CVE-2022-36113](https://github.com/rust-lang/cargo/security/advisories/GHSA-rfj2-q3h3-hm5j) | cargo | Extracting malicious crates can corrupt arbitrary files | 早於 1.64.0 | [1.64.0](/rust-1-64) |
| [CVE-2022-36114](https://github.com/rust-lang/cargo/security/advisories/GHSA-2hvr-h6gw-qrxp) | cargo | Extracting malicious crates can fill the file system | 早於 1.64.0 | [1.64.0](/rust-1-64) |
| [CVE-2022-21658](https://github.com/rust-lang/rust/security/advisories/GHSA-r9cc-f5pr-p3j2) | std | Race condition in std::fs::remove_dir_all | 早於 1.58.1 | [1.58.1](/rust-1-58) |
| [CVE-2021-42574](https://github.com/rust-lang/rust/security/advisories/GHSA-rcv6-wg5m-24v6) | rustc | rustc and bidirectional-override codepoints in source code | 早於 1.56.1 | [1.56.1](/rust-1-56) |
| [CVE-2021-28878](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-28878) | std | Zip may call __iterator_get_unchecked twice with the same index | 1.14.0 起，早於 1.52.0 | [1.52.0](/rust-1-52) |
| [CVE-2021-28879](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-28879) | std | Zip can cause buffer overflow when a consumed Zip iterator is used again | 1.14.0 起，早於 1.52.0 | [1.52.0](/rust-1-52) |
| [CVE-2021-28876](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-28876) | std | Panic safety issue in Zip specialization | 1.14.0 起，早於 1.52.0 | [1.52.0](/rust-1-52) |
| [CVE-2021-28877](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-28877) | std | TrustedRandomAccess specialization composes incorrectly for nested iter::Zips | 1.11.0 起，早於 1.51.0 | [1.51.0](/rust-1-51) |
| [CVE-2021-29922](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-29922) | std | Improper Input Validation of octal literals in `std::net` | 早於 1.53.0 | [1.53.0](/rust-1-53) |
| [CVE-2019-16760](https://github.com/rust-lang/rust/security/advisories/GHSA-phjm-8x66-qw4r) | cargo | Cargo prior to Rust 1.26.0 may download the wrong dependency | 早於 1.26.0 | [1.26.0](/rust-1-26) |
| [CVE-2018-1000657](https://github.com/rust-lang/rust/issues/44800) | std | Buffer overflow vulnerability in VecDeque::reserve() | 1.3.0 起，早於 1.22.0 | [1.22.0](/rust-1-22) |
| [CVE-2018-1000622](https://groups.google.com/forum/#!topic/rustlang-security-announcements/4ybxYLTtXuM) | rustdoc | Uncontrolled search path element vulnerability in rustdoc plugins | 早於 1.27.1 | [1.27.1](/rust-1-27) |
| [CVE-2018-25008](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-25008) | std | Insufficient synchronization in `Arc::get_mut` | 1.3.0 起，早於 1.29.0 | [1.29.0](/rust-1-29) |
| [CVE-2017-20004](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-20004) | std | MutexGuard\<Cell\<i32\>\> must not be Sync | 早於 1.19.0 | [1.19.0](/rust-1-19) |

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

## 資料來源

- [Rust 1.14 Release Notes](https://doc.rust-lang.org/stable/releases.html#version-1140-2016-12-22)
- [Rust 1.14 發布公告](https://blog.rust-lang.org/releases/1.14.0/)
- [rust-lang/rust 原始碼 1.14.0](https://github.com/rust-lang/rust/tree/1.14.0)
