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.
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.
11 #![feature(specialization)]
13 // Tests a variety of basic specialization scenarios and method
17 fn foo(&self) -> &'static str;
20 default impl<T> Foo for T {
21 fn foo(&self) -> &'static str {
26 default impl<T: Clone> Foo for T {
27 fn foo(&self) -> &'static str {
32 default impl<T, U> Foo for (T, U) where T: Clone, U: Clone {
33 fn foo(&self) -> &'static str {
38 default impl<T: Clone> Foo for (T, T) {
39 fn foo(&self) -> &'static str {
40 "generic uniform pair"
44 default impl Foo for (u8, u32) {
45 fn foo(&self) -> &'static str {
50 default impl Foo for (u8, u8) {
51 fn foo(&self) -> &'static str {
56 default impl<T: Clone> Foo for Vec<T> {
57 fn foo(&self) -> &'static str {
62 impl Foo for Vec<i32> {
63 fn foo(&self) -> &'static str {
69 fn foo(&self) -> &'static str {
75 fn foo(&self) -> &'static str {
83 default impl<T: Clone + MyMarker> Foo for T {
84 fn foo(&self) -> &'static str {
85 "generic Clone + MyMarker"
90 struct MarkedAndClone;
91 impl MyMarker for MarkedAndClone {}
94 assert!(NotClone.foo() == "generic");
95 assert!(0u8.foo() == "generic Clone");
96 assert!(vec![NotClone].foo() == "generic");
97 assert!(vec![0u8].foo() == "generic Vec");
98 assert!(vec![0i32].foo() == "Vec<i32>");
99 assert!(0i32.foo() == "i32");
100 assert!(String::new().foo() == "String");
101 assert!(((), 0).foo() == "generic pair");
102 assert!(((), ()).foo() == "generic uniform pair");
103 assert!((0u8, 0u32).foo() == "(u8, u32)");
104 assert!((0u8, 0u8).foo() == "(u8, u8)");
105 assert!(MarkedAndClone.foo() == "generic Clone + MyMarker");