trait B<T> {}
impl<T> B<T> for T {}
fn f<K>()
where
u32: B<K>
{
get(&1u32); // #1 error
}
fn get<Q>(k: &Q)
where
u32: B<Q>,
{
}
fn main() {}
In this example, the compiler reports that #1
is an error. The diagnosis says:
= note: expected reference
&K
found reference&u32
However, when calling get(&1u32)
, the type parameter Q
of get
can be inferred to u32
and the trait bound u32:B<Q>
can be satisfied due to the blanket implementations. If I had called get::<K>(&1u32)
at #1
, I would understand the error.
I wonder how the type parameter of the caller associates with the callee function. I didn't find any clue in the Rust Reference about this point.