2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2018-08-31 13:02:01 +00:00
|
|
|
#![allow(non_camel_case_types)]
|
|
|
|
|
2014-10-17 13:13:12 +00:00
|
|
|
// Test that we pick which version of `foo` to run based on the
|
|
|
|
// type that is (ultimately) inferred for `x`.
|
2014-03-05 23:28:08 +00:00
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2012-07-11 22:00:40 +00:00
|
|
|
trait foo {
|
2015-01-25 21:05:03 +00:00
|
|
|
fn foo(&self) -> i32;
|
2012-07-11 22:00:40 +00:00
|
|
|
}
|
|
|
|
|
2015-01-25 21:05:03 +00:00
|
|
|
impl foo for Vec<u32> {
|
|
|
|
fn foo(&self) -> i32 {1}
|
2012-05-25 15:42:39 +00:00
|
|
|
}
|
|
|
|
|
2015-01-25 21:05:03 +00:00
|
|
|
impl foo for Vec<i32> {
|
|
|
|
fn foo(&self) -> i32 {2}
|
2014-10-17 13:13:12 +00:00
|
|
|
}
|
|
|
|
|
2015-01-25 21:05:03 +00:00
|
|
|
fn call_foo_uint() -> i32 {
|
2014-10-17 13:13:12 +00:00
|
|
|
let mut x = Vec::new();
|
|
|
|
let y = x.foo();
|
2015-01-25 21:05:03 +00:00
|
|
|
x.push(0u32);
|
2014-10-17 13:13:12 +00:00
|
|
|
y
|
|
|
|
}
|
|
|
|
|
2015-01-25 21:05:03 +00:00
|
|
|
fn call_foo_int() -> i32 {
|
2014-10-17 13:13:12 +00:00
|
|
|
let mut x = Vec::new();
|
|
|
|
let y = x.foo();
|
2015-01-25 21:05:03 +00:00
|
|
|
x.push(0i32);
|
2014-10-17 13:13:12 +00:00
|
|
|
y
|
2012-05-25 15:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2014-10-17 13:13:12 +00:00
|
|
|
assert_eq!(call_foo_uint(), 1);
|
|
|
|
assert_eq!(call_foo_int(), 2);
|
2012-07-11 22:00:40 +00:00
|
|
|
}
|