Hi!
So I am trying to emulate something akin to C++'s explicit template specialization in Rust 
The idea of the code below is to have a set of functions (f1 and f2 here) which are defined only for certain combinations of type parameters T and U. On top of that, it should be possible to write generic functions that use f1 and f2 internally (bar).
trait Foo {
type T;
type U;
fn f1(Self::T);
fn f2() -> Self::U;
}
impl Foo for (i32,u32) {
type T = i32;
type U = u32;
fn f1(x: i32) {}
fn f2() -> u32 { 1 }
}
impl Foo for (i64,u64) {
type T = i64;
type U = u64;
fn f1(x: i64) {}
fn f2() -> u64 { 2 }
}
// Should work for (A,B) being either (i32,u32) or (i64,u64).
fn bar<A,B>(x: A) -> B where (A,B): Foo {
<(A,B) as Foo>::f1(x);
<(A,B) as Foo>::f2()
}
fn main() {
let x:u32 = bar(1_i32);
let y:u64 = bar(2_i64);
}
Sadly, this doesn’t compile:
<anon>:21:24: 21:25 error: mismatched types:
expected `<(A, B) as Foo>::T`,
found `A`
(expected associated type,
found type parameter) [E0308]
<anon>:21 <(A,B) as Foo>::f1(x);
^
<anon>:21:24: 21:25 help: see the detailed explanation for E0308
<anon>:22:5: 22:25 error: mismatched types:
expected `B`,
found `<(A, B) as Foo>::U`
(expected type parameter,
found associated type) [E0308]
<anon>:22 <(A,B) as Foo>::f2()
^~~~~~~~~~~~~~~~~~~~
<anon>:22:5: 22:25 help: see the detailed explanation for E0308
error: aborting due to 2 previous errors
Shouldn’t the compiler have figured out that <(A, B) as Foo>::T is the same type as A?