-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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).
Activity
!
to a type (RFC 1216) #35121Auto merge of #68350 - Aaron1011:its-daylight-saving-time, r=<try>
Auto merge of #68350 - Aaron1011:its-daylight-saving-time, r=<try>
Auto merge of #68350 - Aaron1011:its-daylight-saving-time, r=<try>
Auto merge of #68350 - Aaron1011:its-daylight-saving-time, r=<try>
blitzerr commentedon Jun 26, 2020
@rustbot assign
rustbot commentedon Jun 26, 2020
Error: Parsing assign command in comment failed: ...'t assign
' | error: specify user to assign to at >| ''...
Please let
@rust-lang/release
know if you're having trouble with this bot.blitzerr commentedon Jun 26, 2020
@rustbot assign @blitzerr
blitzerr commentedon Jun 26, 2020
Mentoring instructions here
blitzerr commentedon Jun 26, 2020
Playground link
I found this RFC helpful to understand what this feature is in the first place and explains my grave unfamiliarity with Rust.
!
type #79366nikomatsakis commentedon Nov 24, 2020
@rustbot claim
I've opened #79366 which introduces a modified form of fallback that addresses this problem.
HKalbasi commentedon Sep 1, 2021
Mark-Simulacrum commentedon Oct 24, 2021
I'm going to close this issue, since we have landed a version of #79366 (gated under never_type_fallback still) and it seems pretty clear at this point we cannot stabilize never type without fallback changes.