]>
Commit | Line | Data |
---|---|---|
416331ca | 1 | // run-pass |
b039eaaf | 2 | // Ensure that a user-defined type admits multiple inherent methods |
c34b1796 AL |
3 | // with the same name, which can be called on values that have a |
4 | // precise enough type to allow distinguishing between the methods. | |
5 | ||
c34b1796 AL |
6 | |
7 | struct Foo<T>(T); | |
8 | ||
9 | impl Foo<usize> { | |
10 | fn bar(&self) -> i32 { self.0 as i32 } | |
11 | } | |
12 | ||
13 | impl Foo<isize> { | |
14 | fn bar(&self) -> i32 { -(self.0 as i32) } | |
15 | } | |
16 | ||
17 | fn main() { | |
18 | let foo_u = Foo::<usize>(5); | |
19 | assert_eq!(foo_u.bar(), 5); | |
20 | ||
21 | let foo_i = Foo::<isize>(3); | |
22 | assert_eq!(foo_i.bar(), -3); | |
23 | } |