To !
This discusses the semantics for coercion into !
from some expression.
Currently, these rules largely come down to coercion to !
being possible
"after" an expression with !
type is encountered, such as return
or break
.
FIXME: It seems like this may have subtle differences as the divergence checking is done on HIR(?) but MIR may end up lowered into a different order -- should write out the rules and check more thoroughly. Relevant code:
-
compiler/rustc_typeck/src/check/fn_ctxt/checks.rs:720
If we have definitely diverged, then a missing tail expression does not force the return type to be()
(i.e., the implicit expression is not present).
FIXME: the above example does not feel obviously related to !
, there's
probably some more reading and digging to do here.
Examples pulled from src/test/ui/coercion/coerce-to-bang.rs
and src/test/ui/coercion/coerce-to-bang-cast.rs
.
See some background/discussion in rust-lang/rust#40800.
From !
Any coercion site with !
as the "from" type always succeeds, with the
destination type being the new type. This includes inference variables.