Rust: When Empty Isn't Bottom
In August 2026, Rust introduced the empty type to its language, which is represented by the symbol ! or never. Prior to this change, Rust could use ! for function return types, but not for other type annotations. This new feature mostly functions as expected, but there is a surprising aspect: expressions containing ! in their type do not necessarily convert to other types.
The empty type, abbreviated as !, contains no values or constructors. A function named absurd is created to handle values of type !, which takes any value of that type and returns something of the desired type. However, since there are no values of type !, calling this function is never required.
In contrast to the empty type, the bottom type also lacks values and constructors. Nonetheless, it employs subtyping and is considered a subtype of all other types. This difference arises because Rust does not support subtyping for all types, unlike Scala, which calls the empty type Nothing and utilizes subtyping. Consequently, in Rust, a panic! is used to return !, as the language lacks subtyping and requires the absurd function to handle such cases.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.