]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/trait-default-method-xc.rs
Imported Upstream version 1.0.0~beta.3
[rustc.git] / src / test / run-pass / trait-default-method-xc.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2014 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.
970d7e83 10
1a4d82fc 11// aux-build:trait_default_method_xc_aux.rs
970d7e83 12
c34b1796
AL
13
14extern crate trait_default_method_xc_aux as aux;
1a4d82fc
JJ
15use aux::{A, TestEquality, Something};
16use aux::B;
970d7e83
LB
17
18fn f<T: aux::A>(i: T) {
19 assert_eq!(i.g(), 10);
20}
21
c34b1796 22fn welp<T>(i: isize, _x: &T) -> isize {
1a4d82fc
JJ
23 i.g()
24}
970d7e83 25
1a4d82fc 26mod stuff {
c34b1796 27 pub struct thing { pub x: isize }
1a4d82fc
JJ
28}
29
30impl A for stuff::thing {
c34b1796 31 fn f(&self) -> isize { 10 }
970d7e83
LB
32}
33
34fn g<T, U, V: B<T>>(i: V, j: T, k: U) -> (T, U) {
35 i.thing(j, k)
36}
37
38fn eq<T: TestEquality>(lhs: &T, rhs: &T) -> bool {
39 lhs.test_eq(rhs)
40}
41fn neq<T: TestEquality>(lhs: &T, rhs: &T) -> bool {
42 lhs.test_neq(rhs)
43}
44
45
1a4d82fc
JJ
46impl TestEquality for stuff::thing {
47 fn test_eq(&self, rhs: &stuff::thing) -> bool {
970d7e83
LB
48 //self.x.test_eq(&rhs.x)
49 eq(&self.x, &rhs.x)
50 }
51}
52
53
1a4d82fc 54pub fn main() {
970d7e83 55 // Some tests of random things
85aaf69f 56 f(0);
970d7e83 57
85aaf69f 58 assert_eq!(A::lurr(&0, &1), 21);
970d7e83 59
1a4d82fc
JJ
60 let a = stuff::thing { x: 0 };
61 let b = stuff::thing { x: 1 };
62 let c = Something { x: 1 };
970d7e83 63
85aaf69f 64 assert_eq!(0.g(), 10);
1a4d82fc
JJ
65 assert_eq!(a.g(), 10);
66 assert_eq!(a.h(), 11);
67 assert_eq!(c.h(), 11);
970d7e83 68
85aaf69f
SL
69 assert_eq!(0.thing(3.14f64, 1), (3.14f64, 1));
70 assert_eq!(B::staticthing(&0, 3.14f64, 1), (3.14f64, 1));
c34b1796 71 assert_eq!(B::<f64>::staticthing::<isize>(&0, 3.14, 1), (3.14, 1));
970d7e83 72
85aaf69f
SL
73 assert_eq!(g(0, 3.14f64, 1), (3.14f64, 1));
74 assert_eq!(g(false, 3.14f64, 1), (3.14, 1));
970d7e83
LB
75
76
77 // Trying out a real one
85aaf69f
SL
78 assert!(12.test_neq(&10));
79 assert!(!10.test_neq(&10));
970d7e83
LB
80 assert!(a.test_neq(&b));
81 assert!(!a.test_neq(&a));
82
85aaf69f
SL
83 assert!(neq(&12, &10));
84 assert!(!neq(&10, &10));
970d7e83
LB
85 assert!(neq(&a, &b));
86 assert!(!neq(&a, &a));
87}