3 #![feature(specialization)] //~ WARN the feature `specialization` is incomplete
5 // Tests a variety of basic specialization scenarios and method
9 fn foo(&self) -> &'static str;
13 default fn foo(&self) -> &'static str {
18 impl<T: Clone> Foo for T {
19 default fn foo(&self) -> &'static str {
24 impl<T, U> Foo for (T, U) where T: Clone, U: Clone {
25 default fn foo(&self) -> &'static str {
30 impl<T: Clone> Foo for (T, T) {
31 default fn foo(&self) -> &'static str {
32 "generic uniform pair"
36 impl Foo for (u8, u32) {
37 default fn foo(&self) -> &'static str {
42 impl Foo for (u8, u8) {
43 default fn foo(&self) -> &'static str {
48 impl<T: Clone> Foo for Vec<T> {
49 default fn foo(&self) -> &'static str {
54 impl Foo for Vec<i32> {
55 fn foo(&self) -> &'static str {
61 fn foo(&self) -> &'static str {
67 fn foo(&self) -> &'static str {
75 impl<T: Clone + MyMarker> Foo for T {
76 default fn foo(&self) -> &'static str {
77 "generic Clone + MyMarker"
82 struct MarkedAndClone;
83 impl MyMarker for MarkedAndClone {}
86 assert!(NotClone.foo() == "generic");
87 assert!(0u8.foo() == "generic Clone");
88 assert!(vec![NotClone].foo() == "generic");
89 assert!(vec![0u8].foo() == "generic Vec");
90 assert!(vec![0i32].foo() == "Vec<i32>");
91 assert!(0i32.foo() == "i32");
92 assert!(String::new().foo() == "String");
93 assert!(((), 0).foo() == "generic pair");
94 assert!(((), ()).foo() == "generic uniform pair");
95 assert!((0u8, 0u32).foo() == "(u8, u32)");
96 assert!((0u8, 0u8).foo() == "(u8, u8)");
97 assert!(MarkedAndClone.foo() == "generic Clone + MyMarker");