Infallible is not as bad as it sounds
Infallible is not as bad as it sounds
Posted Sep 9, 2026 7:58 UTC (Wed) by NYKevin (subscriber, #129325)Parent article: Stabilizing Rust's never type
Infallible is (was) defined as an empty enum, and Rust knows very well that empty enums cannot be instantiated. For example, you can legally write something like the following:
let Ok(s) = String::FromStr("hello world!");
Note the complete lack of an Err case. This works even without the never type stabilization, because Rust knows the Err() case can't really exist. If this is known early enough for the above code to type-check successfully, then it obviously should also be known at trans (which is much later in the compilation process).
The real problem with Infallible is mostly that it has a silly name and does not auto-coerce at all. The latter can be worked around by writing match(x) {} where x is (or contains) an Infallible. The match statement does not require arms because (again) Rust knows that there are no possible values to match against, and does not require any match arms. This expression will coerce into an arbitrary type. But that's more unwieldy than using !, which auto-coerces and doesn't require this workaround.
