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