]> git.proxmox.com Git - rustc.git/blob - src/test/auxiliary/specialization_cross_crate.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / auxiliary / specialization_cross_crate.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 #![feature(specialization)]
12
13 pub trait Foo {
14 fn foo(&self) -> &'static str;
15 }
16
17 impl<T> Foo for T {
18 default fn foo(&self) -> &'static str {
19 "generic"
20 }
21 }
22
23 impl<T: Clone> Foo for T {
24 default fn foo(&self) -> &'static str {
25 "generic Clone"
26 }
27 }
28
29 impl<T, U> Foo for (T, U) where T: Clone, U: Clone {
30 default fn foo(&self) -> &'static str {
31 "generic pair"
32 }
33 }
34
35 impl<T: Clone> Foo for (T, T) {
36 default fn foo(&self) -> &'static str {
37 "generic uniform pair"
38 }
39 }
40
41 impl Foo for (u8, u32) {
42 default fn foo(&self) -> &'static str {
43 "(u8, u32)"
44 }
45 }
46
47 impl Foo for (u8, u8) {
48 default fn foo(&self) -> &'static str {
49 "(u8, u8)"
50 }
51 }
52
53 impl<T: Clone> Foo for Vec<T> {
54 default fn foo(&self) -> &'static str {
55 "generic Vec"
56 }
57 }
58
59 impl Foo for Vec<i32> {
60 fn foo(&self) -> &'static str {
61 "Vec<i32>"
62 }
63 }
64
65 impl Foo for String {
66 fn foo(&self) -> &'static str {
67 "String"
68 }
69 }
70
71 impl Foo for i32 {
72 fn foo(&self) -> &'static str {
73 "i32"
74 }
75 }
76
77 pub trait MyMarker {}
78 impl<T: Clone + MyMarker> Foo for T {
79 default fn foo(&self) -> &'static str {
80 "generic Clone + MyMarker"
81 }
82 }