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。- 新增
str::split_whitespace,依 Unicode 空白切開字串,詳見 &str。 mpsc::Receiver實作IntoIterator,可以直接用for走訪收到的訊息,詳見 std::sync::mpsc。Ipv4Addr可以用From<u32>從u32建立,詳見 std::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。 - 編譯器能以 MUSL 取代 glibc 建置工具鏈(實驗性),產生靜態連結、無相依的執行檔。
- 編譯器定義
target_envcfg,用來區分同平台的不同工具鏈(如gnu、musl)。 - 更多錯誤附上修改建議,延伸說明也能在線上查閱。
相容性注意
- 依照算術溢位政策,啟用除錯斷言(debug assertions)時
abs溢位會 panic,詳見 整數。
split_whitespace 切開單字
split(' ') 只認一個空白字元,連續空白、tab、換行都會產生空字串或殘留;split_whitespace 把任何長度的 Unicode 空白都當成分隔,也會忽略開頭與結尾的空白,是解析使用者輸入最常用的方法。範例:
- 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);
- }
輸出:
- ["cargo", "build", "--release"]
- 共 3 個字
- ["", "", "cargo", "", "", "build\t--release\n"]
用 for 接收通道訊息
Receiver 實作 IntoIterator 後,for value in rx 會不斷等待並取出訊息,直到所有傳送端都被丟棄、通道關閉才結束迴圈,不必自己寫 loop 加 recv。範例:
- 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!("通道已關閉");
- }
輸出:
- 收到 10
- 收到 20
- 收到 30
- 通道已關閉
注意:只要還有任何一個
Sender 活著,for 迴圈就會一直等下去;把 tx move 進執行緒,執行緒結束時 tx 被丟棄,迴圈才會結束。本版新增的棄用 API
以下 API 從 Rust 1.1 起標記為棄用(deprecated),新程式不要再使用;說明欄為官方原文。
| 模組 | 項目 | 官方說明 |
|---|---|---|
std::fs | soft_link | 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 | 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-29922 | std | Improper Input Validation of octal literals in std::net | 早於 1.53.0 | 1.53.0 |
| CVE-2019-16760 | cargo | Cargo prior to Rust 1.26.0 may download the wrong dependency | 早於 1.26.0 | 1.26.0 |
| CVE-2018-1000622 | rustdoc | Uncontrolled search path element vulnerability in rustdoc plugins | 早於 1.27.1 | 1.27.1 |
| CVE-2017-20004 | std | MutexGuard<Cell<i32>> must not be Sync | 早於 1.19.0 | 1.19.0 |
| CVE-2015-20001 | std | Panic safety violation in BinaryHeap | 早於 1.2.0 | 1.2.0 |
本版已停止支援,不會再修正這些漏洞;請升級到
1.100.1。