]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/traits-repeated-supertrait.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[rust.git] / src / test / run-pass / traits-repeated-supertrait.rs
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 that we can invoke the
13 // various methods in various ways successfully.
14 // See also `compile-fail/trait-repeated-supertrait-ambig.rs`.
15
16 // pretty-expanded FIXME #23616
17
18 trait CompareTo<T> {
19     fn same_as(&self, t: T) -> bool;
20 }
21
22 trait CompareToInts : CompareTo<i64> + CompareTo<u64> {
23 }
24
25 impl CompareTo<i64> for i64 {
26     fn same_as(&self, t: i64) -> bool { *self == t }
27 }
28
29 impl CompareTo<u64> for i64 {
30     fn same_as(&self, t: u64) -> bool { *self == (t as i64) }
31 }
32
33 impl CompareToInts for i64 { }
34
35 fn with_obj(c: &CompareToInts) -> bool {
36     c.same_as(22_i64) && c.same_as(22_u64)
37 }
38
39 fn with_trait<C:CompareToInts>(c: &C) -> bool {
40     c.same_as(22_i64) && c.same_as(22_u64)
41 }
42
43 fn with_ufcs1<C:CompareToInts>(c: &C) -> bool {
44     CompareToInts::same_as(c, 22_i64) && CompareToInts::same_as(c, 22_u64)
45 }
46
47 fn with_ufcs2<C:CompareToInts>(c: &C) -> bool {
48     CompareTo::same_as(c, 22_i64) && CompareTo::same_as(c, 22_u64)
49 }
50
51 fn main() {
52     assert_eq!(22_i64.same_as(22_i64), true);
53     assert_eq!(22_i64.same_as(22_u64), true);
54     assert_eq!(with_trait(&22), true);
55     assert_eq!(with_obj(&22), true);
56     assert_eq!(with_ufcs1(&22), true);
57     assert_eq!(with_ufcs2(&22), true);
58 }