]> git.proxmox.com Git - rustc.git/blob - src/test/ui/traits/inheritance/repeated-supertrait-ambig.rs
New upstream version 1.52.0~beta.3+dfsg1
[rustc.git] / src / test / ui / traits / inheritance / repeated-supertrait-ambig.rs
1 // Test a case of a trait which extends the same supertrait twice, but
2 // with difference type parameters. Test then that when we don't give
3 // enough information to pick between these, no selection is made. In
4 // this particular case, the two choices are i64/u64 -- so when we use
5 // an integer literal, we wind up falling this literal back to i32.
6 // See also `run-pass/trait-repeated-supertrait.rs`.
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) //~ ERROR `dyn CompareToInts: CompareTo<i32>` is not satisfied
27 }
28
29 fn with_trait<C:CompareToInts>(c: &C) -> bool {
30 c.same_as(22) //~ ERROR `C: CompareTo<i32>` is not satisfied
31 }
32
33 fn with_ufcs1<C:CompareToInts>(c: &C) -> bool {
34 <dyn CompareToInts>::same_as(c, 22) //~ ERROR `dyn CompareToInts: CompareTo<i32>` is not satisfi
35 }
36
37 fn with_ufcs2<C:CompareToInts>(c: &C) -> bool {
38 CompareTo::same_as(c, 22) //~ ERROR `C: CompareTo<i32>` is not satisfied
39 }
40
41 fn main() {
42 assert_eq!(22_i64.same_as(22), true); //~ ERROR `i64: CompareTo<i32>` is not satisfied
43 }