]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/multidispatch2.rs
auto merge of #19648 : mquandalle/rust/patch-1, r=alexcrichton
[rust.git] / src / test / run-pass / multidispatch2.rs
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.
10
11 use std::fmt::Show;
12 use std::default::Default;
13
14 trait MyTrait<T> {
15     fn get(&self) -> T;
16 }
17
18 impl<T> MyTrait<T> for T
19     where T : Default
20 {
21     fn get(&self) -> T {
22         Default::default()
23     }
24 }
25
26 struct MyType {
27     dummy: uint
28 }
29
30 impl Copy for MyType {}
31
32 impl MyTrait<uint> for MyType {
33     fn get(&self) -> uint { self.dummy }
34 }
35
36 fn test_eq<T,M>(m: M, v: T)
37 where T : Eq + Show,
38       M : MyTrait<T>
39 {
40     assert_eq!(m.get(), v);
41 }
42
43 pub fn main() {
44     test_eq(22u, 0u);
45
46     let value = MyType { dummy: 256 + 22 };
47     test_eq(value, value.dummy);
48 }