Series: The Rust Annals
Vol. I Issue 73 nlopes.dev
Announcing Rust 1.72.0
Rust 1.72 removes the fixed limit on const evaluation while retaining feedback and a deny-by-default lint for long-running work. It also makes feature- and platform-gated items visible in compiler diagnostics, moves several correctness and undefined-behavior checks from Clippy into rustc, and stabilizes standard-library and const APIs.
Diagnostics now identify cfg-disabled items
Code can use cfg to expose functions only with particular crate features or on particular platforms. Such items were previously effectively invisible to the compiler. Rust 1.72 remembers their names and cfg conditions, allowing an unresolved-import error to explain that the requested item exists but requires a feature:
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
Const evaluation no longer has a fixed statement limit
Rust previously limited the number of statements executed by any one constant evaluation to prevent compile-time infinite loops or otherwise unbounded work. Creative code could reach that limit, and compilation could begin failing merely because a library function split one statement into two.
Const evaluation may now perform an unlimited amount of work. The compiler still provides feedback: after compile-time code has run for a while, it emits a message and repeats it after intervals that double each time. After a large number of steps it also emits the deny-by-default const_eval_long_running lint to catch infinite loops. Code that intentionally requires especially long evaluation can use allow(const_eval_long_running).
Clippy checks move into rustc with staged defaults
Rust 1.72 brings four groups of Clippy checks into rustc:
undropped_manually_dropsis denied by default. BecauseManuallyDropdoes not drop its inner value, passing it tostd::mem::dropdoes nothing. The lint suggestsManuallyDrop::into_inner; unsafeManuallyDrop::dropcan instead run the destructor in place.invalid_from_utf8_uncheckedis denied by default. It detects invalid UTF-8 literals passed tostd::str::from_utf8_uncheckedorstd::str::from_utf8_unchecked_mut, which violates their safety preconditions and results in undefined behavior.invalid_from_utf8warns about the corresponding calls tostd::str::from_utf8andstd::str::from_utf8_mut, which will always return an error.invalid_nan_comparisonswarns when either operand isf32::NANorf64::NAN. NaN does not compare meaningfully even with itself, so these comparisons are always false; the lint suggestsis_nan().invalid_reference_castingdetects casts from&Tto&mut Twithout interior mutability. This is immediate undefined behavior even when the resulting reference is unused. The lint is currently allowed by default because of potential false positives, but was planned to become deny-by-default in 1.73 after implementation improvements.
Standard-library stabilization extends sharing, conversion, allocation, and const C strings
The newly stable standard-library surface includes a Sync implementation for mpsc::Sender<T> when T: Send, a borrowed conversion from &OsStr to &str, and an operation for leaking a String. The four CStr entries in the API inventory are newly stable specifically in const contexts; the other three entries are newly stable APIs.