Skip to content

without fallback, never type introduces regressions #67225

@nikomatsakis

Description

@nikomatsakis
Contributor

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

added 4 commits that reference this issue on Jan 18, 2020
873f3b0
1d7e91c
76a99da
e60d9e0
blitzerr

blitzerr commented on Jun 26, 2020

@blitzerr
Contributor

@rustbot assign

rustbot

rustbot commented on Jun 26, 2020

@rustbot
Collaborator

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

blitzerr commented on Jun 26, 2020

@blitzerr
Contributor
blitzerr

blitzerr commented on Jun 26, 2020

@blitzerr
Contributor

Mentoring instructions here

blitzerr

blitzerr commented on Jun 26, 2020

@blitzerr
Contributor

Playground link

I found this RFC helpful to understand what this feature is in the first place and explains my grave unfamiliarity with Rust.

nikomatsakis

nikomatsakis commented on Nov 24, 2020

@nikomatsakis
ContributorAuthor

@rustbot claim

I've opened #79366 which introduces a modified form of fallback that addresses this problem.

HKalbasi

HKalbasi commented on Sep 1, 2021

@HKalbasi
Mark-Simulacrum

Mark-Simulacrum commented on Oct 24, 2021

@Mark-Simulacrum
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

F-never_type`#![feature(never_type)]`T-langRelevant to the language team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @nikomatsakis@Mark-Simulacrum@blitzerr@HKalbasi@rustbot

    Issue actions

      without fallback, never type introduces regressions · Issue #67225 · rust-lang/rust