Description
When we attempted to stabilize the never type (!
) in #65355, we encountered unexpected regressions (#66757). These regressions resulted from this canonical test, soon to be in the repo as src/test/never_type/never-value-fallback-issue-66757.rs
. The heart of the test is:
struct E;
impl From<!> for E {
fn from(_: !) -> E {
E
}
}
#[allow(unreachable_code)]
fn foo(never: !) {
<E as From<!>>::from(never); // Ok
<E as From<_>>::from(never); // Inference fails here
}
The problem here is that the never
variable, when referenced, gets assigned a fresh diverging type variable as its type. In the second call, that type variable is unconstrained, and hence it falls back -- to ()
. This leads to a compilation error.
We need to resolve this. @SimonSapin did a great job of outlining the alternatives here. The current preference is probably to enable the new never type fallback. If that should fail, we could consider altering the fallback for rvalues of !
type from those of diverging expressions, as described here, but that will require more discussion to reach consensus (there are other options too, see Simon's comment).