Closed
Description
I kind of expected this to work:
#![feature(generic_associated_types)]
use std::fmt::Debug;
trait Family {
type Member<'a>:
'a +
Debug +
for<'b> PartialEq<Self::Member<'b>>;
}
struct I32;
impl Family for I32 {
type Member<'a> = i32;
}
struct StrRef;
impl Family for StrRef {
type Member<'a> = &'a str;
}
fn check<'a, 'b, F: Family>(a: F::Member<'a>, b: F::Member<'b>) {
assert_eq!(a, b);
}
fn main() {
check::<I32>(0, 0);
}
However it fails with:
error[E0308]: mismatched types
--> src/main.rs:17:5
|
17 | type Member<'a> = i32;
| ^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected associated type `<I32 as Family>::Member<'a>`
found associated type `<I32 as Family>::Member<'b>`
error[E0308]: mismatched types
--> src/main.rs:23:5
|
23 | type Member<'a> = &'a str;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected associated type `<StrRef as Family>::Member<'a>`
found associated type `<StrRef as Family>::Member<'b>`
For more information about this error, try `rustc --explain E0308`.
cc @jackh726
EDIT: I am not 100% sure but this may has to do with the variance of the gat.