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_env cfg,用來區分同平台的不同工具鏈(如 gnu、musl)。
  • 更多錯誤附上修改建議,延伸說明也能在線上查閱。

相容性注意


  • 依照算術溢位政策,啟用除錯斷言(debug assertions)時 abs 溢位會 panic,詳見 整數。

split_whitespace 切開單字


split(' ') 只認一個空白字元,連續空白、tab、換行都會產生空字串或殘留;split_whitespace 把任何長度的 Unicode 空白都當成分隔,也會忽略開頭與結尾的空白,是解析使用者輸入最常用的方法。
範例:
  1. fn main() {
  2. let line = " cargo build\t--release\n";
  3. let words: Vec<&str> = line.split_whitespace().collect();
  4. println!("{:?}", words);
  5. println!("共 {} 個字", words.len());
  6. let by_space: Vec<&str> = line.split(' ').collect();
  7. println!("{:?}", by_space);
  8. }

輸出:
  1. ["cargo", "build", "--release"]
  2. 共 3 個字
  3. ["", "", "cargo", "", "", "build\t--release\n"]

用 for 接收通道訊息


Receiver 實作 IntoIterator 後,for value in rx 會不斷等待並取出訊息,直到所有傳送端都被丟棄、通道關閉才結束迴圈,不必自己寫 loop 加 recv。
範例:
  1. use std::sync::mpsc;
  2. use std::thread;
  3. fn main() {
  4. let (tx, rx) = mpsc::channel();
  5. let worker = thread::spawn(move || {
  6. for i in 1..=3 {
  7. tx.send(i * 10).unwrap();
  8. }
  9. });
  10. for value in rx {
  11. println!("收到 {}", value);
  12. }
  13. worker.join().unwrap();
  14. println!("通道已關閉");
  15. }

輸出:
  1. 收到 10
  2. 收到 20
  3. 收到 30
  4. 通道已關閉

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

本版新增的棄用 API


以下 API 從 Rust 1.1 起標記為棄用(deprecated),新程式不要再使用;說明欄為官方原文。
模組項目官方說明
std::fssoft_linkreplaced 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-5222cargoCargo can be coerced to share credentials between registries早於 1.96.01.96.0
CVE-2026-5223cargoCrates in third party registries can override the cached source of other crates早於 1.96.01.96.0
CVE-2024-43402stdstd::process::Command batch files argument escaping could be bypassed with trailing whitespace or periods早於 1.81.01.81.0
CVE-2024-24576stdstd::process::Command did not properly escape arguments of batch files on Windows早於 1.77.21.77.2
CVE-2023-38497cargoCargo not respecting umask when extracting crate archives早於 1.71.11.71.1
CVE-2022-46176cargoCargo did not verify SSH host keys早於 1.66.11.66.1
CVE-2022-36113cargoExtracting malicious crates can corrupt arbitrary files早於 1.64.01.64.0
CVE-2022-36114cargoExtracting malicious crates can fill the file system早於 1.64.01.64.0
CVE-2022-21658stdRace condition in std::fs::remove_dir_all早於 1.58.11.58.1
CVE-2021-42574rustcrustc and bidirectional-override codepoints in source code早於 1.56.11.56.1
CVE-2021-29922stdImproper Input Validation of octal literals in std::net早於 1.53.01.53.0
CVE-2019-16760cargoCargo prior to Rust 1.26.0 may download the wrong dependency早於 1.26.01.26.0
CVE-2018-1000622rustdocUncontrolled search path element vulnerability in rustdoc plugins早於 1.27.11.27.1
CVE-2017-20004stdMutexGuard<Cell<i32>> must not be Sync早於 1.19.01.19.0
CVE-2015-20001stdPanic safety violation in BinaryHeap早於 1.2.01.2.0

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

資料來源