LANGUAGES Signal 124
Rust's new ! type is an empty type, not bottom, so nested ! won't coerce
Illustration only Photo by Eugen Str on Unsplash
Rust's recently added ! type behaves as an empty type rather than a bottom type, so coercion only works for top-level ! expressions, not when ! is nested inside other types like function pointers.
For Rust developers, this means that while you can use ! in any type annotation, you cannot rely on implicit coercion when ! appears inside a larger type, such as a function pointer. This makes some code more verbose, requiring explicit coercion at the point where the ! value is used. Understanding the distinction between empty and bottom types helps avoid surprises when writing generic or higher-order functions.
Written by elseif from the cluster below · every claim links back to a sourceThe three things worth knowing
Rust now allows the never type ! in all type annotations, not just return types.
Unlike a bottom type, Rust's ! does not coerce when nested inside other types like function pointers.
To use a nested !, you must explicitly coerce the value at the point of use, as Rust lacks subtyping.
THE CLUSTER