]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/traits/traits-repeated-supertrait.rs
391d19c4385586c7277447c8d32eea66e6cfd036
[rustc.git] / src / test / run-pass / traits / traits-repeated-supertrait.rs
1 // run-pass
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.
5 // See also `compile-fail/trait-repeated-supertrait-ambig.rs`.
6
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
25 fn with_obj(c: &dyn CompareToInts) -> bool {
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 {
34 CompareToInts::same_as(c, 22_i64) && CompareToInts::same_as(c, 22_u64)
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 }