]> git.lizzy.rs Git - rust.git/blob - tests/ui/impl-inherent-non-conflict.rs
Modify existing bounds if they exist
[rust.git] / tests / ui / impl-inherent-non-conflict.rs
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> {
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 }