trait Foo<T> {}
trait Bar<A> {
fn method<B>(&self) where A: Foo<B>;
}
struct S;
struct K;
struct X;
struct Z;
impl Foo<S> for X {}
impl Foo<K> for Z {}
impl Bar<X> for isize {
fn method<U>(&self) where X: Foo<U> {
}
}
impl Bar<Z> for isize {
fn method<U>(&self) where Z: Foo<U> {
}
}
fn main() {
1is.method::<S>();
}
compile time error:
where-clause-method-substituion.rs:35:9: 35:22 error: unable to infer enough type information about `_`; type annotations required
where-clause-method-substituion.rs:35 1is.method::<S>();
^~~~~~~~~~~~~
This is a valid error, the compiler can’t figure out if you want A = X or A = Z - maybe it could be clearer about that, but your example isn’t likely to ever compile.
You can still call it using, e.g. Bar::<X>::method::<S>(&1is).
It seems odd that the identifier _ would appear in the error message, given that it doesn’t appear in the original code. Is there an explanation for that? (Even if there is, that’s a misleading error message.)
I believe the inference variable tracks its source, which in this case is a type parameter.
I'm not sure how much work it would be, but it should be possible to have it say:
could not infer enough type information about this instantiation of type parameter A from trait foo::bar::Bar"