]> git.lizzy.rs Git - rust.git/blob - src/test/ui/methods/method-ambig-one-trait-unknown-int-type.rs
move an `assert!` to the right place
[rust.git] / src / test / ui / methods / method-ambig-one-trait-unknown-int-type.rs
1 // Test that we invoking `foo()` successfully resolves to the trait `Foo`
2 // (prompting the mismatched types error) but does not influence the choice
3 // of what kind of `Vec` we have, eventually leading to a type error.
4
5 trait Foo {
6     fn foo(&self) -> isize;
7 }
8
9 impl Foo for Vec<usize> {
10     fn foo(&self) -> isize {1}
11 }
12
13 impl Foo for Vec<isize> {
14     fn foo(&self) -> isize {2}
15 }
16
17 // This is very hokey: we have heuristics to suppress messages about
18 // type annotations needed. But placing these two bits of code into
19 // distinct functions, in this order, causes us to print out both
20 // errors I'd like to see.
21
22 fn m1() {
23     // we couldn't infer the type of the vector just based on calling foo()...
24     let mut x = Vec::new();
25     //~^ ERROR type annotations needed
26     x.foo(); //~ ERROR type annotations needed
27 }
28
29 fn m2() {
30     let mut x = Vec::new();
31
32     // ...but we still resolved `foo()` to the trait and hence know the return type.
33     let y: usize = x.foo(); //~ ERROR mismatched types
34 }
35
36 fn main() { }