Rust 1.38
最後更新
Rust 1.38 發布於 2019-09-26,目前最新修補版為
1.38.0,已停止支援,請升級到 1.100.1。版本介紹
Rust 1.38 的重點是管線化編譯(pipelined compilation):相依的 crate 只要完成型別資訊與 metadata,下游 crate 就能開始編譯,不必等上游的程式碼產生結束,多 crate 專案的建置時間在部分情況下明顯縮短,而且不需要任何設定。同一版也新增了
std::any::type_name,並讓 rustc 對已知會造成未定義行為的 mem::uninitialized、mem::zeroed 用法發出警告。語言變更
#[global_allocator]可以用在子模組中。#[deprecated]可以標在巨集上。
標準庫重點
any::type_name取得型別名稱的字串,主要用於除錯,詳見 std::any。Duration新增as_secs_f32、as_secs_f64、from_secs_f32、from_secs_f64、mul_f32、mul_f64、div_f32、div_f64,以浮點數表示或運算時間,詳見 std::time。- 所有數值型別新增歐幾里得除法
div_euclid與餘數rem_euclid,整數另有checked、overflowing、wrapping版本,詳見 數值。 - 原始指標新增
<*const T>::cast與<*mut T>::cast,詳見 std::ptr。 Clone、Debug等 prelude trait 的 derive 巨集可以用和 trait 相同的路徑取得,例如std::clone::Clone;內建巨集也都能從std根取得,例如std::include_bytes!。Arc<[T]>與Rc<[T]>實作FromIterator<T>;iter::StepBy、Peekable、Take實作DoubleEndedIterator。slice::concat、join可以接受&[T]作為分隔或元素。
Cargo 與工具
- Cargo 支援管線化編譯。
--features可以重複傳入多次來啟用多個 feature。- rustdoc:
pub use上的文件會加在被重新匯出項目的文件前面。
相容性注意
rustc1.38.0 無法建置x86_64-unknown-uefi平台;armv7-unknown-linux-gnueabihf平台與libc等部分 crate 已知有問題。
std::any::type_name
type_name::<T>() 回傳型別名稱的字串,搭配泛型可以看出編譯器推斷出的實際型別,對理解泛型與型別推斷很有幫助。官方文件說明輸出格式不保證穩定,只能用於除錯,不要拿來比對或當作識別碼。範例的 Vec<u8> 印成 alloc::vec::Vec<u8>,顯示出它實際定義在 alloc crate。範例:
- use std::any::type_name;
- fn name_of<T>(_: &T) -> &'static str {
- type_name::<T>()
- }
- fn main() {
- println!("{}", type_name::<i32>());
- println!("{}", name_of(&vec![1u8]));
- println!("{}", name_of(&"hi"));
- }
輸出:
- i32
- alloc::vec::Vec<u8>
- &str
Duration 的浮點運算與歐幾里得除法
Duration::from_secs_f64(1.5) 直接用秒數建立時間長度,mul_f64、div_f32 讓「乘以倍率」不必先換算成奈秒。歐幾里得除法則處理負數:一般的 % 結果和被除數同號,-7 % 3 是 -1;rem_euclid 永遠回傳非負數,-7 對 3 取餘得 2,計算循環索引時特別好用。範例:
- use std::time::Duration;
- fn main() {
- let d = Duration::from_secs_f64(1.5);
- println!("{:?}", d);
- println!("{}", d.as_secs_f64());
- println!("{:?}", d.mul_f64(2.0));
- println!("{:?}", d.div_f32(4.0));
- println!("{} {}", -7 % 3, (-7i32).rem_euclid(3));
- println!("{} {}", -7 / 3, (-7i32).div_euclid(3));
- }
輸出:
- 1.5s
- 1.5
- 3s
- 375ms
- -1 2
- -2 -3
注意:
Duration::from_secs_f64 傳入負數、NaN 或超出範圍的值會 panic。本版新增的棄用 API
以下 API 從 Rust 1.38 起標記為棄用(deprecated),新程式不要再使用;說明欄為官方原文。
| 模組 | 項目 | 官方說明 |
|---|---|---|
std::sync | ONCE_INIT | the Once::new() function is now preferred |
修補版本
本版沒有修補版本。
已知漏洞
影響
1.38.0 的已知漏洞共 18 個;在本版修正的共 0 個;仍影響最新修補版 1.38.0 的共 18 個。官方未公布影響範圍的漏洞只列在修正它的版本,不計入其他版本。仍影響 1.38.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-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-2020-36317 | std | String::retain allows safely creating invalid strings when abusing panic | 1.26.0 起,早於 1.49.0 | 1.49.0 |
| CVE-2021-29922 | std | Improper Input Validation of octal literals in std::net | 早於 1.53.0 | 1.53.0 |
本版已停止支援,不會再修正這些漏洞;請升級到
1.100.1。