]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs
New upstream version 1.17.0+dfsg1
[rustc.git] / src / test / compile-fail / method-ambig-one-trait-unknown-int-type.rs
CommitLineData
d9579d0f 1// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
1a4d82fc
JJ
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11// Test that we invoking `foo()` successfully resolves to the trait `foo`
12// (prompting the mismatched types error) but does not influence the choice
13// of what kind of `Vec` we have, eventually leading to a type error.
14
15trait foo {
16 fn foo(&self) -> isize;
17}
18
19impl foo for Vec<usize> {
20 fn foo(&self) -> isize {1}
21}
22
23impl foo for Vec<isize> {
24 fn foo(&self) -> isize {2}
25}
26
27// This is very hokey: we have heuristics to suppress messages about
28// type annotations required. But placing these two bits of code into
29// distinct functions, in this order, causes us to print out both
30// errors I'd like to see.
31
32fn m1() {
33 // we couldn't infer the type of the vector just based on calling foo()...
d9579d0f 34 let mut x = Vec::new();
8bb4bdeb 35 //~^ ERROR type annotations needed [E0282]
1a4d82fc
JJ
36 x.foo();
37}
38
39fn m2() {
40 let mut x = Vec::new();
41
42 // ...but we still resolved `foo()` to the trait and hence know the return type.
43 let y: usize = x.foo(); //~ ERROR mismatched types
44}
45
46fn main() { }