diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 1308c0dc..4d1a297a 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -372,3 +372,4 @@ - [1.69](appendix/rust-versions/1.69.md) - [1.70](appendix/rust-versions/1.70.md) - [1.71](appendix/rust-versions/1.71.md) + - [1.72](appendix/rust-versions/1.72.md) diff --git a/src/appendix/rust-versions/1.72.md b/src/appendix/rust-versions/1.72.md new file mode 100644 index 00000000..720f0f8c --- /dev/null +++ b/src/appendix/rust-versions/1.72.md @@ -0,0 +1,61 @@ +# Rust 新版解读 | 1.72 | feature启用提示 + +> Rust 1.72 官方 release doc: [Announcing Rust 1.72.0 | Rust Blog](https://blog.rust-lang.org/2023/08/24/Rust-1.72.0.html) + +通过 [rustup](https://www.rust-lang.org/tools/install) 安装的同学可以使用以下命令升级到 1.72 版本: + +```shell +$ rustup update stable +``` + +## 警告可能有用的 `cfg` 禁用项 + +一直以来都支持的通过 `cfg` 条件编译部分代码,例如在开启特定 feature 时的函数,或者针对特定平台的逻辑。之前编译器会直接无视掉这些代码,现在会记录这些符号名称和对应的 `cfg` 条件,因此可以警告你正在调用一个特定 feature 下的函数,需要启用 feature: + +```text + Compiling my-project v0.1.0 (/tmp/my-project) +error[E0432]: unresolved import `rustix::io_uring` + --> src/main.rs:1:5 + | +1 | use rustix::io_uring; + | ^^^^^^^^^^^^^^^^ no `io_uring` in the root + | +note: found an item that was configured out + --> /home/username/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustix-0.38.8/src/lib.rs:213:9 + | +213 | pub mod io_uring; + | ^^^^^^^^ + = note: the item is gated behind the `io_uring` feature + +For more information about this error, try `rustc --explain E0432`. +error: could not compile `my-project` (bin "my-project") due to previous error +``` + +## 不受限制的常量计算时间 + +之前为了避免用户自定义的常量在编译期间进行估算时,陷入死循环或占用无限制的时间,Rust 之前会限制用作常量计算的语句数目。然而一些特殊的有创造性的 Rust 代码还是会超过这个限制,进而产生编译错误;更糟糕的情况是,是否达到限制的是会随着用户调用库的不同而变化的。 + +现在,可以在编译时执行无限制的常量计算。而为了避免长时间编译没有反馈,编译器会在编译时代码运行一段时间后发出一条消息,并在每次翻倍的一段时间后重复该消息。默认情况下,编译器还将在捕获无限循环的大量步骤后报错提示 `const_eval_long_run` ,但可以用 `allow(const_eval_long_run)` 允许特别长的常量计算。 + +## Clippy lints 上升到 rustc + +几个原本由 Clippy 提供的 lints,提升到 rustc 里: + +* [`clippy::undropped_manually_drops`](https://rust-lang.github.io/rust-clippy/rust-1.71.0/index.html#undropped_manually_drops) => [undropped-manually-drops](https://doc.rust-lang.org/1.72.0/rustc/lints/listing/deny-by-default.html#undropped-manually-drops) (deny) + * 无作用的 `ManullyDrop` +* [`clippy::invalid_utf8_in_unchecked`](https://rust-lang.github.io/rust-clippy/rust-1.71.0/index.html#invalid_utf8_in_unchecked) => [`invalid_from_utf8_unchecked`](https://doc.rust-lang.org/1.72.0/rustc/lints/listing/deny-by-default.html#invalid-from-utf8-unchecked) (deny) 或 [`invalid_from_utf8`](https://doc.rust-lang.org/1.72.0/rustc/lints/listing/warn-by-default.html#invalid-from-utf8) (warn) + * 检查调用 `std::str::from_utf8_unchecked` 和 `std::str::from_utf8_unchecked_mut` 转换不合法的 UTF-8 字面量,这会违反了 safety 前提,导致未定义行为 + * 检查 `std::str::from_utf8` 和 `std::str::from_utf8_mut` 转换不合法的 UTF-8 字面量,这会永远返回错误。 +* [`clippy::cmp_nan`](https://rust-lang.github.io/rust-clippy/rust-1.71.0/index.html#cmp_nan) => [`invalid_nan_comparisons`](https://doc.rust-lang.org/1.72.0/rustc/lints/listing/warn-by-default.html#invalid-nan-comparisons) (warn) + * 检查使用 `f32::NAN` 或者 `f64::NAN` 参与比较,`NAN` 在比较时无任何意义,即使与自己比较也是无意义行为,建议使用 `is_nan()` 方法 +* [`clippy::cast_ref_to_mut`](https://rust-lang.github.io/rust-clippy/rust-1.71.0/index.html#cast_ref_to_mut) => [`invalid_reference_casting`](https://doc.rust-lang.org/1.72.0/rustc/lints/listing/allowed-by-default.html#invalid-reference-casting) (allow) + * 检查不使用内部可变性的从 `&T` 到 `&mut T` 的转换,这会导致未定义行为。当前这个lint本身还有些问题,所以是 `allow` 级别,预计会在 1.73 版本修正后变为默认 `deny` + +## 未来对 Windows 的支持 + +未来的 release 版本里会放弃对 win10 以前的系统的官方支持,Rust 1.75 将成为最后一个支持 windows 7,8,8.1的版本,2024 年 2 月起的 rust 1.76 将仅支持 win10 及后续版本 ( target : tier-1 )。详情见提案 [MCP 651](https://github.com/rust-lang/compiler-team/issues/651) + + +## Others + +其它更新细节,和稳定的API列表,参考[原Blog](https://blog.rust-lang.org/2023/08/24/Rust-1.72.0.html#stabilized-apis)