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