# Rust 1.44

Rust 1.44 發布於 2020-06-04，目前最新修補版為 `1.44.1`，**已停止支援**，請升級到 `1.100.1`。

## 版本介紹

Rust 1.44 是一個小版本，官方公告的兩大重點是 Cargo 內建 `cargo tree`，以樹狀圖顯示整個相依關係，以及 `async`/`.await` 可以在 `#![no_std]` 環境中使用。標準庫新增 `Vec<T>` 從陣列建立的轉換與 `PathBuf` 的容量管理方法。升級時要注意：下一版（1.45）起，`f64` 以 `as` 轉成整數會改為飽和轉換，需要舊行為時改用新穩定的 `to_int_unchecked`。

### 語言變更

- `async`/`.await` 可以在 `#![no_std]` 中使用，詳見 [async 基礎](/async-basics)。
- 新增 `unused_braces` lint，提醒不必要的大括號。
- 被 `cfg` 排除的外部模組（`mod baz;`）即使檔案不存在也能解析，語意上仍會被拒絕。

### 標準庫重點

- `Vec<T>` 實作 `From<[T; N]>`（`N` 最多 32），詳見 [Vec](/pkg-vec)。
- `vec![]` 直接對應 `Vec::new()`，可以用在 `const` 情境中。
- `PathBuf` 新增 `with_capacity`、`capacity`、`clear`、`reserve`、`reserve_exact`、`shrink_to_fit`，詳見 [std::path](/pkg-path)。
- `f32::to_int_unchecked`、`f64::to_int_unchecked` 不檢查範圍地轉成整數，詳見 [f64](/pkg-f64)。
- `Layout::align_to`、`pad_to_align`、`array`、`extend` 穩定。
- `String` 實作 `From<&mut str>`；`OsString` 實作 `DerefMut` 與 `IndexMut`；`IoSlice` 實作 `Copy`；`convert::Infallible` 實作 `Hash`。
- 整數的 `from_le_bytes`、`to_le_bytes` 等位元組轉換方法改為 `const fn`；支援 Unicode 13。

### Cargo 與工具

- 新增 `cargo tree` 顯示相依樹；`cargo tree -d`（`--duplicates`）列出同一個 crate 的多個版本，詳見 [開發工具](/modules-tools)。
- rustdoc 可以用 `--crate-version` 在側邊欄顯示版本。
- 增量編譯模式下 `rustc` 會遵守 `-C codegen-units`，預設使用 256 個 codegen unit。

### 相容性注意

- `mem::zeroed` 與 `mem::uninitialized` 用在不允許全零初始化的型別（如 `NonZeroU8`）時改為 panic，以前只是警告。
- Windows GNU 目標產生的靜態函式庫副檔名改為 `.a`，不再是 `.lib`。
- 移除 `rustc` 的 `-C no_integrated_as` 旗標；外部 LLVM 最低版本提高到 LLVM 8。

### Vec::from 陣列與 const 的 vec![]

`Vec::from([3, 1, 2])` 直接把陣列轉成向量，不必先轉切片再 `to_vec()`。`String::from` 也能接受 `&mut str`。因為空的 `vec![]` 會直接展開成 `Vec::new()`，它可以寫在 `const` 裡。

範例：

```rust
fn main() {
    let v: Vec<i32> = Vec::from([3, 1, 2]);
    println!("{:?}", v);

    let mut owned = String::from("abc");
    let s: String = String::from(owned.as_mut_str());
    println!("{}", s);

    const EMPTY: Vec<u8> = vec![];
    println!("{}", EMPTY.len());
}
```

輸出：

```text
[3, 1, 2]
abc
0
```

### PathBuf 容量管理與 to_int_unchecked

`PathBuf` 的內部是可增長的緩衝區，現在可以像 `String` 一樣預先配置容量、清空後重複使用。範例後半示範 `to_int_unchecked` 與 1.45 起的飽和轉換：`300.0 as u8` 得到上限 `255`、`-1.0 as u8` 得到下限 `0`，不再是未定義行為。

範例：

```rust
use std::path::PathBuf;

fn main() {
    let mut path = PathBuf::with_capacity(64);
    println!("{}", path.capacity() >= 64);
    path.push("logs");
    path.push("app.log");
    println!("{}", path.display());
    path.clear();
    println!("[{}]", path.display());

    let x = 3.9_f64;
    let n: i32 = unsafe { x.to_int_unchecked() };
    println!("{}", n);
    println!("{} {}", 300.0_f64 as u8, -1.0_f64 as u8);
}
```

輸出：

```text
true
logs/app.log
[]
3
255 0
```

注意：`to_int_unchecked` 是 `unsafe` 方法，值是 NaN、無窮大或超出目標型別範圍時屬於未定義行為；只在已確定值落在範圍內、且需要極致效能時使用，一般轉換用 `as` 或 `TryFrom`。

## 本版新增的棄用 API

本版沒有新增棄用 API。

## 修補版本

| 版本 | 發布日期 | 含安全修補 | 內容（官方原文） |
| --- | --- | --- | --- |
| `1.44.1` | 2020-06-18 | 否 | rustfmt accepts rustfmt_skip in cfg_attr again.；Don't hash executable filenames on apple platforms, fixing backtraces.；Fix crashes when finding backtrace on macOS.；Clippy applies lint levels into different files. |

## 已知漏洞

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

### 仍影響 `1.44.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) |
| [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-28875](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-28875) | std | Logic bug in Read can cause buffer overflow in read_to_end() | 1.20.0 起，早於 1.50.0 | [1.50.0](/rust-1-50) |
| [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-2020-36323](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-36323) | std | API soundness issue in join() implementation of \[Borrow\<str\>\] | 1.28.0 起，早於 1.52.0 | [1.52.0](/rust-1-52) |
| [CVE-2020-36317](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-36317) | std | String::retain allows safely creating invalid strings when abusing panic | 1.26.0 起，早於 1.49.0 | [1.49.0](/rust-1-49) |
| [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) |

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

## 資料來源

- [Rust 1.44 Release Notes](https://doc.rust-lang.org/stable/releases.html#version-1440-2020-06-04)
- [Rust 1.44 發布公告](https://blog.rust-lang.org/releases/1.44.0/)
- [rust-lang/rust 原始碼 1.44.0](https://github.com/rust-lang/rust/tree/1.44.0)
