Series: The Rust Annals
Vol. I Issue 78 nlopes.dev
Announcing Rust 1.77.0
Rust 1.77 makes foreign-function code easier to check with C-string literals and permits recursive async fn calls when indirection keeps the future finite-sized. It also stabilizes offset_of! for obtaining public struct-field offsets without an instance, while Cargo now strips standard-library debuginfo from release outputs that do not request debuginfo.
C-string literals check nul-terminated data at compile time
Rust now supports C-string literals such as c"abc". They expand to a nul-byte-terminated string in memory with type &'static CStr, making it easier to write code that interoperates with foreign-language interfaces requiring nul-terminated strings.
The relevant checks happen at compile time, including rejecting an interior nul byte.
Recursive async functions work with indirection
Async functions previously could not call themselves because of a compiler limitation. Rust 1.77 lifts that limitation: recursive calls are permitted provided they use some form of indirection to avoid making the function state infinitely large.
For example, boxing the recursive calls makes this function valid:
async fn fib(n: u32) -> u32 {
match n {
0 | 1 => 1,
_ => Box::pin(fib(n-1)).await + Box::pin(fib(n-2)).await
}
}
offset_of! obtains field offsets without an instance
Rust 1.77 stabilizes offset_of! for struct fields. It provides the byte offset of a public field and is particularly useful when no instance of the type is available. Although this was already possible on stable Rust, doing it without an instance required tricky unsafe code in which it was easy to introduce undefined behavior accidentally.
offset_of!(StructName, field) expands to a usize expression containing the field's byte offset from the start of the struct.
Cargo strips debuginfo when release profiles do not request it
Cargo profiles that do not enable debuginfo in their outputs—for example, profiles using debug = 0—now enable strip = "debuginfo" by default.
The precompiled standard library ships with debuginfo, so statically linked results could previously include standard-library debuginfo even when local compilations did not explicitly request it. Users who want debuginfo can explicitly enable it with the debug flag in the relevant Cargo profile.