Skip to content

Instantly share code, notes, and snippets.

@japaric
Created November 24, 2014 22:29
Show Gist options
  • Save japaric/18749abe5b8a3cfbc798 to your computer and use it in GitHub Desktop.
Save japaric/18749abe5b8a3cfbc798 to your computer and use it in GitHub Desktop.
default_type_params inference failure
#![feature(default_type_params)]
enum Enum<L = (), R = ()> {
Both(L, R),
Left(L),
Right(R),
}
fn main() {
// I'm expecting the compiler to choose the type `Enum<u8, ()>` here
let left = Enum::Left(0u8);
//^~ error: unable to infer enough type information about `Enum<u8, _>`; type annotations required
// and the type `Enum<(), u8>` here, because `Enum` has default type parameters
let right = Enum::Right(0u8);
//^~ error: unable to infer enough type information about `Enum<_>`; type annotations required
// But instead, I need to hint the default type parameters...
let left: Enum<_, ()> = Enum::Left(0u8); // OK
let right: Enum<(), _> = Enum::Right(0u8); // OK
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment