]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
c34b1796 AL |
2 | // Test a case of a trait which extends the same supertrait twice, but |
3 | // with difference type parameters. Test that we can invoke the | |
4 | // various methods in various ways successfully. | |
5869c6ff | 5 | // See also `ui/traits/trait-repeated-supertrait-ambig.rs`. |
c34b1796 | 6 | |
c34b1796 AL |
7 | |
8 | trait CompareTo<T> { | |
9 | fn same_as(&self, t: T) -> bool; | |
10 | } | |
11 | ||
12 | trait CompareToInts : CompareTo<i64> + CompareTo<u64> { | |
13 | } | |
14 | ||
15 | impl CompareTo<i64> for i64 { | |
16 | fn same_as(&self, t: i64) -> bool { *self == t } | |
17 | } | |
18 | ||
19 | impl CompareTo<u64> for i64 { | |
20 | fn same_as(&self, t: u64) -> bool { *self == (t as i64) } | |
21 | } | |
22 | ||
23 | impl CompareToInts for i64 { } | |
24 | ||
dc9dc135 | 25 | fn with_obj(c: &dyn CompareToInts) -> bool { |
c34b1796 AL |
26 | c.same_as(22_i64) && c.same_as(22_u64) |
27 | } | |
28 | ||
29 | fn with_trait<C:CompareToInts>(c: &C) -> bool { | |
30 | c.same_as(22_i64) && c.same_as(22_u64) | |
31 | } | |
32 | ||
33 | fn with_ufcs1<C:CompareToInts>(c: &C) -> bool { | |
6a06907d | 34 | <dyn CompareToInts>::same_as(c, 22_i64) && <dyn CompareToInts>::same_as(c, 22_u64) |
c34b1796 AL |
35 | } |
36 | ||
37 | fn with_ufcs2<C:CompareToInts>(c: &C) -> bool { | |
38 | CompareTo::same_as(c, 22_i64) && CompareTo::same_as(c, 22_u64) | |
39 | } | |
40 | ||
41 | fn main() { | |
42 | assert_eq!(22_i64.same_as(22_i64), true); | |
43 | assert_eq!(22_i64.same_as(22_u64), true); | |
44 | assert_eq!(with_trait(&22), true); | |
45 | assert_eq!(with_obj(&22), true); | |
46 | assert_eq!(with_ufcs1(&22), true); | |
47 | assert_eq!(with_ufcs2(&22), true); | |
48 | } |