Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Ralith opened this issue Nov 9, 2016 · 1 comment
Closed

Comments

@Ralith
Copy link
Contributor

Ralith commented Nov 9, 2016

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

@eddyb
Copy link
Member

eddyb commented Nov 9, 2016

That error is correct, ! is not a subtype of i32 (in the olden days this was true and caused many ICEs).
EDIT: That is, the error conforms to the accepted rust-lang/rfcs#1216.

@eddyb eddyb closed this as completed Nov 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants