What Is New in Rust 1.76
| Category | Highlights |
|---|---|
| New Features | char and u32 are now ABI-compatible; std::any::type_name_of_val(&T) added for runtime type names. |
What ABI compatibility changes were introduced in Rust 1.76?
Rust 1.76 guarantees that the primitive types char and u32 are ABI-compatible.
This change formalizes a relationship that already existed in size and alignment, allowing them to be used interchangeably in FFI function signatures without undefined behavior. In practice, you can now declare extern functions that accept either type and rely on the compiler to treat them as equivalent.
Watch out for code that previously performed manual casts between char and u32 for ABI reasons; those casts are now redundant.
How can I retrieve a type's name from a value in Rust 1.76?
Rust 1.76 provides std::any::type_name_of_val(&value) to obtain a readable type name at runtime.
This function works with any reference, including closures and opaque return types, eliminating the need for an explicit generic parameter.
fn get_iter() -> impl Iterator- {
[1, 2, 3].into_iter()
}
fn main() {
let iter = get_iter();
let iter_name = std::any::type_name_of_val(&iter);
let sum: i32 = iter.sum();
println!("The sum of the `{}` is {}.", iter_name, sum);
}
The example prints something like core::array::iter::IntoIter<i32, 3>, giving you insight during debugging or logging.
Which APIs were stabilized in Rust 1.76?
Rust 1.76 stabilizes a handful of previously nightly-only APIs, most notably the new type_name_of_val function.
These stabilizations expand the standard library's introspection capabilities and reduce the need for workarounds in production code. The release also updates the function-pointer documentation to clarify ABI compatibility rules.
Most teams can adopt the new APIs immediately without waiting for a future nightly.
Frequently Asked Questions
Does upgrading to Rust 1.76 require changes to existing code?
Most code will compile unchanged unless it relied on the undocumented ABI difference between char and u32.
How do I upgrade my toolchain to Rust 1.76?
Run rustup update stable.
Can I use type_name_of_val in a no_std environment?
Yes the function is available in core and does not depend on the standard library.
Will the new ABI guarantee affect my FFI bindings?
The guarantee makes it safe to treat char and u32 interchangeably in extern "C" function signatures.
Where can I find the full list of stabilized APIs in 1.76?
The Rust blog release notes contain the complete list of changes.