]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/traits-repeated-supertrait-ambig.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / traits-repeated-supertrait-ambig.rs
CommitLineData
c34b1796
AL
1// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11// Test a case of a trait which extends the same supertrait twice, but
12// with difference type parameters. Test then that when we don't give
13// enough information to pick between these, no selection is made. In
14// this particular case, the two choices are i64/u64 -- so when we use
15// an integer literal, we wind up falling this literal back to i32.
16// See also `run-pass/trait-repeated-supertrait.rs`.
17
18trait CompareTo<T> {
19 fn same_as(&self, t: T) -> bool;
20}
21
22trait CompareToInts : CompareTo<i64> + CompareTo<u64> {
23}
24
25impl CompareTo<i64> for i64 {
26 fn same_as(&self, t: i64) -> bool { *self == t }
27}
28
29impl CompareTo<u64> for i64 {
30 fn same_as(&self, t: u64) -> bool { *self == (t as i64) }
31}
32
33impl CompareToInts for i64 { }
34
35fn with_obj(c: &CompareToInts) -> bool {
54a0048b 36 c.same_as(22) //~ ERROR `CompareToInts: CompareTo<i32>` is not satisfied
c34b1796
AL
37}
38
39fn with_trait<C:CompareToInts>(c: &C) -> bool {
54a0048b 40 c.same_as(22) //~ ERROR `C: CompareTo<i32>` is not satisfied
c34b1796
AL
41}
42
43fn with_ufcs1<C:CompareToInts>(c: &C) -> bool {
54a0048b 44 CompareToInts::same_as(c, 22) //~ ERROR `CompareToInts: CompareTo<i32>` is not satisfied
c34b1796
AL
45}
46
47fn with_ufcs2<C:CompareToInts>(c: &C) -> bool {
54a0048b 48 CompareTo::same_as(c, 22) //~ ERROR `C: CompareTo<i32>` is not satisfied
c34b1796
AL
49}
50
51fn main() {
54a0048b 52 assert_eq!(22_i64.same_as(22), true); //~ ERROR `i64: CompareTo<i32>` is not satisfied
c34b1796 53}