Closed
Description
As far as I can tell, this is a legitimate bug, and I have not been able to find any similar reports on github.
I have a project where I have greatly simplified my codebase using associated_type_defaults. However, it seems like the type checker can't figure out that the literal type of the default case is the same as the default case. I have condensed my problem to the following test-case.
I feel both variants should definitely be valid, since the default is clearly Self. Have I misunderstood something, or is this a bug?
#![feature(associated_type_defaults)]
// rustc 1.19.0-nightly (f1140a331 2017-05-08)
pub struct Foo;
pub trait CanDecode {
type Output = Self;
fn read(rdr: &mut Foo) -> Option<Self::Output>;
}
impl CanDecode for u8 {
fn read(rdr: &mut Foo) -> Option<Self::Output> { Some(42) }
}
impl CanDecode for u16 {
fn read(rdr: &mut Foo) -> Option<u16> { Some(17) }
}
/*
error[E0053]: method `read` has an incompatible type for trait
--> yo_dawg_i_heard_you_like_traits.rs:14:31
|
6 | fn read(rdr: &mut Foo) -> Option<Self::Output>;
| -------------------- type in trait
...
14 | fn read(rdr: &mut Foo) -> Option<u16> { Some(17) }
| ^^^^^^^^^^^ expected associated type, found u16
|
= note: expected type `fn(&mut Foo) -> std::option::Option<<u16 as CanDecode>::Output>`
found type `fn(&mut Foo) -> std::option::Option<u16>`
error: aborting due to previous error
*/