Skip to content

without fallback, never type introduces regressions #67225

Closed
@nikomatsakis

Description

@nikomatsakis

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).

Metadata

Metadata

Assignees

Labels

F-never_type`#![feature(never_type)]`T-langRelevant to the language team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions