]> git.proxmox.com Git - rustc.git/blob - src/test/ui/methods/method-two-trait-defer-resolution-1.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / methods / method-two-trait-defer-resolution-1.rs
1 // run-pass
2 #![allow(non_camel_case_types)]
3
4 // Test that we pick which version of `foo` to run based on the
5 // type that is (ultimately) inferred for `x`.
6
7
8 trait foo {
9 fn foo(&self) -> i32;
10 }
11
12 impl foo for Vec<u32> {
13 fn foo(&self) -> i32 {1}
14 }
15
16 impl foo for Vec<i32> {
17 fn foo(&self) -> i32 {2}
18 }
19
20 fn call_foo_uint() -> i32 {
21 let mut x = Vec::new();
22 let y = x.foo();
23 x.push(0u32);
24 y
25 }
26
27 fn call_foo_int() -> i32 {
28 let mut x = Vec::new();
29 let y = x.foo();
30 x.push(0i32);
31 y
32 }
33
34 fn main() {
35 assert_eq!(call_foo_uint(), 1);
36 assert_eq!(call_foo_int(), 2);
37 }