]> git.proxmox.com Git - rustc.git/blame - src/test/ui/traits/inheritance/repeated-supertrait.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / test / ui / traits / inheritance / repeated-supertrait.rs
CommitLineData
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
8trait CompareTo<T> {
9 fn same_as(&self, t: T) -> bool;
10}
11
12trait CompareToInts : CompareTo<i64> + CompareTo<u64> {
13}
14
15impl CompareTo<i64> for i64 {
16 fn same_as(&self, t: i64) -> bool { *self == t }
17}
18
19impl CompareTo<u64> for i64 {
20 fn same_as(&self, t: u64) -> bool { *self == (t as i64) }
21}
22
23impl CompareToInts for i64 { }
24
dc9dc135 25fn with_obj(c: &dyn CompareToInts) -> bool {
c34b1796
AL
26 c.same_as(22_i64) && c.same_as(22_u64)
27}
28
29fn with_trait<C:CompareToInts>(c: &C) -> bool {
30 c.same_as(22_i64) && c.same_as(22_u64)
31}
32
33fn 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
37fn with_ufcs2<C:CompareToInts>(c: &C) -> bool {
38 CompareTo::same_as(c, 22_i64) && CompareTo::same_as(c, 22_u64)
39}
40
41fn 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}