Skip to content

! (uninhabited type) unification failures when used with higher-order functions #37668

@Ralith

Description

@Ralith
enum Void {}

fn unreachable(x: Void) -> ! {
    match x {}
}

fn frob(x: Option<Void>) -> Option<i32> {
    x.map(unreachable)
}

gives

error[E0308]: mismatched types
 --> void.rs:8:5
  |
8 |     x.map(unreachable)
  |     ^^^^^^^^^^^^^^^^^^ expected i32, found !
  |
  = note: expected type `std::option::Option<i32>`
  = note:    found type `std::option::Option<!>`

Typechecking passes if line 8 is replaced with x.map(|y| unreachable(y)) or if line 3 is replaced with fn unreachable<T>(x: Void) -> T {.

CC @canndrew

Meta

rustc --version --verbose:
rustc 1.14.0-nightly (cae6ab1 2016-11-05)
binary: rustc
commit-hash: cae6ab1
commit-date: 2016-11-05
host: x86_64-unknown-linux-gnu
release: 1.14.0-nightly
LLVM version: 3.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions