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