2 // Test that when we write `x.foo()`, we do not have to know the
3 // complete type of `x` in order to type-check the method call. In
4 // this case, we know that `x: Vec<_1>`, but we don't know what type
5 // `_1` is (because the call to `push` comes later). To pick between
6 // the impls, we would have to know `_1`, since we have to know
7 // whether `_1: MyCopy` or `_1 == Box<i32>`. However (and this is the
8 // point of the test), we don't have to pick between the two impls --
9 // it is enough to know that `foo` comes from the `Foo` trait. We can
10 // codegen the call as `Foo::foo(&x)` and let the specific impl get
14 fn foo(&self) -> isize;
17 trait MyCopy { fn foo(&self) { } }
18 impl MyCopy for i32 { }
20 impl<T:MyCopy> Foo for Vec<T> {
21 fn foo(&self) -> isize {1}
24 impl Foo for Vec<Box<i32>> {
25 fn foo(&self) -> isize {2}
28 fn call_foo_copy() -> isize {
29 let mut x = Vec::new();
35 fn call_foo_other() -> isize {
36 let mut x: Vec<_> = Vec::new();
38 let z: Box<i32> = Box::new(0);
44 assert_eq!(call_foo_copy(), 1);
45 assert_eq!(call_foo_other(), 2);