Rust 1.43
最後更新
Rust 1.43 發布於 2020-04-23,目前最新修補版為
1.43.1,已停止支援,請升級到 1.100.1。版本介紹
Rust 1.43 是一個小版本,重點是巨集的
item 片段可以插入到 trait、impl 與 extern 區塊中,以及整數與浮點數的關聯常數可以直接使用:寫 u32::MAX、f32::NAN 不必再 use std::u32;。數值字面值搭配參考的型別推斷也修正了,Cargo 則為整合測試提供可執行檔路徑的環境變數。升級時要注意:assert! 後面多餘的語法從警告變成錯誤。語言變更
- 巨集的
item片段可以插入trait、impl與extern區塊,詳見 宣告式巨集。 #[cfg()]等屬性可以用在if運算式上。- 修正
&1.0這類對數字取參考後進行二元運算時的型別推斷。 - 幾項僅語法層面的變更(如
type Foo: Ord、所有fn中允許self),語意上仍會被拒絕。
標準庫重點
- 整數與浮點數的關聯常數可以直接使用,例如
u32::MAX、f32::NAN,詳見 整數 與 浮點數。 - 新增
primitive模組重新匯出原生型別,主要讓巨集避免型別名稱被遮蔽。 Once::is_completed與iter::once_with穩定,詳見 std::sync 與 std::iter。- 新增常數
f32::consts::LOG10_2、LOG2_10與f64的對應常數。 Arc<[T; N]>、Box<[T; N]>、Rc<[T; N]>實作從對應切片型別的TryFrom(N為0..=32)。String實作AsMut<str>;FromUtf8Error實作Clone與Eq;u8::is_ascii改為const fn。
Cargo 與工具
.cargo/config或環境變數可以設定[profile]。- 執行整合測試或基準測試時,Cargo 設定
CARGO_BIN_EXE_<name>指向二進位檔的路徑,可以用env!("CARGO_BIN_EXE_my-program")取得,詳見 整合測試。 rustc可以傳入多個 lint 旗標,後面的旗標覆寫前面的,例如-D unused -A unused-variables。
相容性注意
assert!巨集後面有多餘語法改為硬錯誤,自 1.36 起它就是警告。- 修正
Self型別推斷錯誤,部分以前誤被接受的程式碼現在會編譯失敗。
直接使用數值型別的關聯常數
以前取得
u32 的最大值要寫 std::u32::MAX(模組常數)或先 use std::u32;。1.43 起 MAX、MIN、EPSILON、NAN 等都是型別本身的關聯常數,直接寫 u32::MAX、f64::EPSILON 即可。數學常數如 LOG10_2 仍放在 std::f64::consts 模組裡。範例:
- use std::f64::consts::LOG10_2;
- fn main() {
- println!("{}", u32::MAX);
- println!("{}", i8::MIN);
- println!("{}", f64::EPSILON > 0.0);
- println!("{}", f32::NAN.is_nan());
- println!("{:.4}", LOG10_2);
- }
輸出:
- 4294967295
- -128
- true
- true
- 0.3010
在 impl 中插入 item 片段
$x:item 片段比對一個完整的項目(函式、結構體等)。以前它只能放在模組層級,現在可以插進 impl、trait 與 extern 區塊,巨集能夠接收一個方法定義並放進產生的 impl 中。範例:
- macro_rules! with_greet {
- ($name:ident, $method:item) => {
- struct $name;
- impl $name {
- $method
- }
- };
- }
- with_greet!(Robot, fn greet(&self) -> &'static str { "beep" });
- fn main() {
- println!("{}", Robot.greet());
- }
輸出:
- beep
本版新增的棄用 API
本版沒有新增棄用 API。
修補版本
| 版本 | 發布日期 | 含安全修補 | 內容(官方原文) |
|---|---|---|---|
1.43.1 | 2020-05-07 | 是 | Updated openssl-src to 1.1.1g for CVE-2020-1967.;Fixed the stabilization of AVX-512 features.;Fixed cargo package --list not working with unpublished dependencies. |
已知漏洞
影響
1.43.0 的已知漏洞共 18 個;在本版修正的共 1 個;仍影響最新修補版 1.43.1 的共 18 個。官方未公布影響範圍的漏洞只列在修正它的版本,不計入其他版本。本版已修正
| 編號 | 元件 | 摘要(官方原文) | 影響範圍 | 修正於 |
|---|---|---|---|---|
| CVE-2020-1967 | vendored | Updated openssl-src to 1.1.1g for CVE-2020-1967. | 未公布 | 1.43.1 |
仍影響 1.43.1
| 編號 | 元件 | 摘要(官方原文) | 影響範圍 | 修正於 |
|---|---|---|---|---|
| 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。