Closed
Description
I'm reasonably sure the problem below is related to multidispatch and its interaction with type inference. It works fine for a standalone function, but not in an impl
context:
pub trait Borrow<Sized? Borrowed> {
fn borrow(&self) -> &Borrowed;
}
impl<T: Sized> Borrow<T> for T {
fn borrow(&self) -> &T { self }
}
trait Foo {
fn foo(&self, other: &Self);
}
// This works fine
fn bar<K, Q>(k: &K, q: &Q) where K: Borrow<Q>, Q: Foo {
q.foo(k.borrow())
}
struct MyTree<K>;
impl<K> MyTree<K> {
// This fails
fn bar<Q>(k: &K, q: &Q) where K: Borrow<Q>, Q: Foo {
q.foo(k.borrow())
}
}
The error is:
borrow-test.rs:22:15: 22:25 error: mismatched types: expected `&Q`, found `&K` (expected type parameter, found a different type parameter)
borrow-test.rs:22 q.foo(k.borrow())
^~~~~~~~~~
Metadata
Metadata
Assignees
Labels
No labels