# Rust 1.1

Rust 1.1 發布於 2015-06-25，目前最新修補版為 `1.1.0`，**已停止支援**，請升級到 `1.100.1`。

## 版本介紹

Rust 1.1 是 1.0 之後第一個火車週期的成果，重點放在編譯速度與錯誤訊息：以自舉（bootstrapping）編譯器衡量，編譯時間比 1.0 快 32%，大量錯誤附上可用 `--explain` 查看的延伸說明。標準庫擴充了 `std::fs`，Cargo 也能用 `cargo rustc` 把自訂旗標傳給編譯器。對新手來說，這版沒有需要改寫程式的破壞性變更，升級即可。

### 標準庫重點

- `std::fs` 大幅擴充：`DirEntry` 可取得 `file_type` 與 `metadata`（部分平台不需額外系統呼叫），新增 `symlink_metadata`，詳見 [std::fs](/pkg-fs)。
- 新增 `str::split_whitespace`，依 Unicode 空白切開字串，詳見 [&str](/pkg-str)。
- `mpsc::Receiver` 實作 `IntoIterator`，可以直接用 `for` 走訪收到的訊息，詳見 [std::sync::mpsc](/pkg-sync-mpsc)。
- `Ipv4Addr` 可以用 `From<u32>` 從 `u32` 建立，詳見 [std::net](/pkg-net)。
- Unix 的 `std::os::unix::symlink` 建立符號連結；Windows 用 `symlink_dir` 與 `symlink_file`。
- 新的擴充特徵 `FromRawFd`／`AsRawFd`（Windows 為 `FromRawHandle`／`AsRawHandle`）讓 `File`、`TcpStream` 等型別與系統底層 handle 互相轉換。
- 切片的 `count`、`nth`、`last` 改為 *O*(1)；`File` 實作 `Debug`。
- `Cloned` 迭代器在 1.0 時被意外留為不穩定，這版補上穩定。

### Cargo 與工具

- 新增 `cargo rustc`，建置時可把任意旗標傳給最後一次 `rustc` 呼叫，詳見 [Cargo](/modules-cargo)。
- 編譯器能以 MUSL 取代 glibc 建置工具鏈（實驗性），產生靜態連結、無相依的執行檔。
- 編譯器定義 `target_env` cfg，用來區分同平台的不同工具鏈（如 `gnu`、`musl`）。
- 更多錯誤附上修改建議，延伸說明也能在線上查閱。

### 相容性注意

- 依照算術溢位政策，啟用除錯斷言（debug assertions）時 `abs` 溢位會 panic，詳見 [整數](/types-integers)。

### split_whitespace 切開單字

`split(' ')` 只認一個空白字元，連續空白、tab、換行都會產生空字串或殘留；`split_whitespace` 把任何長度的 Unicode 空白都當成分隔，也會忽略開頭與結尾的空白，是解析使用者輸入最常用的方法。

範例：

```rust
fn main() {
    let line = "  cargo   build\t--release\n";
    let words: Vec<&str> = line.split_whitespace().collect();
    println!("{:?}", words);
    println!("共 {} 個字", words.len());

    let by_space: Vec<&str> = line.split(' ').collect();
    println!("{:?}", by_space);
}
```

輸出：

```text
["cargo", "build", "--release"]
共 3 個字
["", "", "cargo", "", "", "build\t--release\n"]
```

### 用 for 接收通道訊息

`Receiver` 實作 `IntoIterator` 後，`for value in rx` 會不斷等待並取出訊息，直到所有傳送端都被丟棄、通道關閉才結束迴圈，不必自己寫 `loop` 加 `recv`。

範例：

```rust
use std::sync::mpsc;
use std::thread;

fn main() {
    let (tx, rx) = mpsc::channel();

    let worker = thread::spawn(move || {
        for i in 1..=3 {
            tx.send(i * 10).unwrap();
        }
    });

    for value in rx {
        println!("收到 {}", value);
    }
    worker.join().unwrap();
    println!("通道已關閉");
}
```

輸出：

```text
收到 10
收到 20
收到 30
通道已關閉
```

注意：只要還有任何一個 `Sender` 活著，`for` 迴圈就會一直等下去；把 `tx` move 進執行緒，執行緒結束時 `tx` 被丟棄，迴圈才會結束。

## 本版新增的棄用 API

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

| 模組 | 項目 | 官方說明 |
| --- | --- | --- |
| `std::fs` | [`soft_link`](https://doc.rust-lang.org/std/fs/fn.soft_link.html) | replaced with std::os::unix::fs::symlink and std::os::windows::fs::{symlink_file, symlink_dir} |

## 修補版本

本版沒有修補版本。

## 已知漏洞

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

### 仍影響 `1.1.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-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-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-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) |
| [CVE-2015-20001](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-20001) | std | Panic safety violation in BinaryHeap | 早於 1.2.0 | [1.2.0](/rust-1-2) |

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

## 資料來源

- [Rust 1.1 Release Notes](https://doc.rust-lang.org/stable/releases.html#version-110-2015-06-25)
- [Rust 1.1 發布公告](https://blog.rust-lang.org/releases/1.1.0/)
- [rust-lang/rust 原始碼 1.1.0](https://github.com/rust-lang/rust/tree/1.1.0)
