Rust 1.49
最後更新
Rust 1.49 發布於 2020-12-31,目前最新修補版為
1.49.0,已停止支援,請升級到 1.100.1。版本介紹
Rust 1.49 把 64 位元 ARM Linux(
aarch64-unknown-linux-gnu)提升到 tier 1,這是第一個達到最高支援等級的非 x86 目標;Apple M1(aarch64-apple-darwin)與 ARM 版 Windows(aarch64-pc-windows-msvc)也進入 tier 2,可以用 rustup 安裝預先編譯好的工具鏈。對新手來說,在 M1 Mac 上寫 Rust 從這版開始有官方發行版;測試框架也會擷取測試中子執行緒的輸出。語言變更
- 同一個模式裡可以混用「以參考綁定」與「以移動綁定」,例如
let Person { name, ref age } = person;,詳見 模式。 - 聯合體(union)可以實作
Drop,欄位可以是ManuallyDrop<T>。 - 沒有任何變體的列舉可以轉型成整數。
標準庫重點
- 新增
slice::select_nth_unstable、select_nth_unstable_by、select_nth_unstable_by_key,詳見 切片。 Poll::is_ready、Poll::is_pending成為const fn,詳見 std::task。RangeInclusive在contains與索引時會檢查是否已耗盡。
Cargo 與工具
- 測試中產生的執行緒輸出會被擷取,只有測試失敗時才顯示,詳見 單元測試。
cargo package產生的套件可重現;cargo tree會標示程序式巨集 crate。- 新增建置期環境變數
CARGO_PRIMARY_PACKAGE;指定套件與目標時可以使用 glob 樣式。 - 最低支援的 LLVM 版本提高到 9。
相容性注意
i686-unknown-freebsd從 host tier 2 降為 target tier 2。- 以分號結尾的巨集呼叫即使展開為空,也一律視為陳述式。
- 列舉變體上部分內建屬性會檢查是否有效,以前被忽略的無效屬性現在會報錯。
- 文件註解開頭空白的去除方式更一致,可能影響輸出;關聯型別不再推斷特徵約束。
在同一個模式裡移動與借用
解構結構體時,可以讓某些欄位被移動出來、其他欄位只借用。下面
name 被移出 person,age 用 ref 借用,所以之後仍能讀取 person.age。範例:
- #[derive(Debug)]
- struct Person {
- name: String,
- age: u8,
- }
- fn main() {
- let person = Person {
- name: String::from("Alice"),
- age: 20,
- };
- let Person { name, ref age } = person;
- println!("{name} {age}");
- println!("{}", person.age);
- }
輸出:
- Alice 20
- 20
注意:
name 已被移走,之後再讀 person.name 或整個 person 都會編譯失敗;觀念詳見 移動與複製。select_nth_unstable
只想找第 k 小的元素(例如中位數)時,不必完整排序。
select_nth_unstable(k) 會重新排列切片,讓索引 k 的位置剛好放第 k 小的值,左邊都不大於它、右邊都不小於它,回傳 (左段, 第 k 個, 右段)。範例:
- fn main() {
- let mut scores = [72, 95, 61, 88, 79, 54, 90];
- let mid = scores.len() / 2;
- let (_, median, _) = scores.select_nth_unstable(mid);
- println!("中位數:{median}");
- let mut words = ["kiwi", "fig", "banana", "apple"];
- let (_, shortest, _) = words.select_nth_unstable_by_key(0, |w| w.len());
- println!("最短:{shortest}");
- }
輸出:
- 中位數:79
- 最短:fig
本版新增的棄用 API
本版沒有新增棄用 API。
修補版本
本版沒有修補版本。
已知漏洞
影響
1.49.0 的已知漏洞共 18 個;在本版修正的共 0 個;仍影響最新修補版 1.49.0 的共 18 個。官方未公布影響範圍的漏洞只列在修正它的版本,不計入其他版本。仍影響 1.49.0
| 編號 | 元件 | 摘要(官方原文) | 影響範圍 | 修正於 |
|---|---|---|---|---|
| CVE-2026-5222 | cargo | Cargo can be coerced to share credentials between registries | 早於 1.96.0 | 1.96.0 |
| CVE-2026-5223 | cargo | Crates in third party registries can override the cached source of other crates | 早於 1.96.0 | 1.96.0 |
| CVE-2024-43402 | std | std::process::Command batch files argument escaping could be bypassed with trailing whitespace or periods | 早於 1.81.0 | 1.81.0 |
| CVE-2024-24576 | std | std::process::Command did not properly escape arguments of batch files on Windows | 早於 1.77.2 | 1.77.2 |
| CVE-2023-38497 | cargo | Cargo not respecting umask when extracting crate archives | 早於 1.71.1 | 1.71.1 |
| CVE-2022-46176 | cargo | Cargo did not verify SSH host keys | 早於 1.66.1 | 1.66.1 |
| CVE-2022-36113 | cargo | Extracting malicious crates can corrupt arbitrary files | 早於 1.64.0 | 1.64.0 |
| CVE-2022-36114 | cargo | Extracting malicious crates can fill the file system | 早於 1.64.0 | 1.64.0 |
| CVE-2022-21658 | std | Race condition in std::fs::remove_dir_all | 早於 1.58.1 | 1.58.1 |
| CVE-2021-42574 | rustc | rustc and bidirectional-override codepoints in source code | 早於 1.56.1 | 1.56.1 |
| CVE-2021-31162 | std | Double free in Vec::from_iter specialization when drop panics | 1.48.0 起,早於 1.52.0 | 1.52.0 |
| CVE-2021-28878 | std | Zip may call __iterator_get_unchecked twice with the same index | 1.14.0 起,早於 1.52.0 | 1.52.0 |
| 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 |
| CVE-2021-28876 | std | Panic safety issue in Zip specialization | 1.14.0 起,早於 1.52.0 | 1.52.0 |
| 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 |
| CVE-2021-28877 | std | TrustedRandomAccess specialization composes incorrectly for nested iter::Zips | 1.11.0 起,早於 1.51.0 | 1.51.0 |
| CVE-2020-36323 | std | API soundness issue in join() implementation of [Borrow<str>] | 1.28.0 起,早於 1.52.0 | 1.52.0 |
| CVE-2021-29922 | std | Improper Input Validation of octal literals in std::net | 早於 1.53.0 | 1.53.0 |
本版已停止支援,不會再修正這些漏洞;請升級到
1.100.1。