1 // run-pass 2 // Ensure that a user-defined type admits multiple inherent methods 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 6 7 struct Foo<T>(T); 8 9 impl Foo<usize> { bar(&self) -> i3210 fn bar(&self) -> i32 { self.0 as i32 } 11 } 12 13 impl Foo<isize> { bar(&self) -> i3214 fn bar(&self) -> i32 { -(self.0 as i32) } 15 } 16 main()17fn 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 } 24