]> git.lizzy.rs Git - rust.git/blob - src/test/ui/specialization/specialization-basics.rs
warn against 'specialization' feature
[rust.git] / src / test / ui / specialization / specialization-basics.rs
1 // run-pass
2
3 #![feature(specialization)] //~ WARN the feature `specialization` is incomplete
4
5 // Tests a variety of basic specialization scenarios and method
6 // dispatch for them.
7
8 trait Foo {
9     fn foo(&self) -> &'static str;
10 }
11
12 impl<T> Foo for T {
13     default fn foo(&self) -> &'static str {
14         "generic"
15     }
16 }
17
18 impl<T: Clone> Foo for T {
19     default fn foo(&self) -> &'static str {
20         "generic Clone"
21     }
22 }
23
24 impl<T, U> Foo for (T, U) where T: Clone, U: Clone {
25     default fn foo(&self) -> &'static str {
26         "generic pair"
27     }
28 }
29
30 impl<T: Clone> Foo for (T, T) {
31     default fn foo(&self) -> &'static str {
32         "generic uniform pair"
33     }
34 }
35
36 impl Foo for (u8, u32) {
37     default fn foo(&self) -> &'static str {
38         "(u8, u32)"
39     }
40 }
41
42 impl Foo for (u8, u8) {
43     default fn foo(&self) -> &'static str {
44         "(u8, u8)"
45     }
46 }
47
48 impl<T: Clone> Foo for Vec<T> {
49     default fn foo(&self) -> &'static str {
50         "generic Vec"
51     }
52 }
53
54 impl Foo for Vec<i32> {
55     fn foo(&self) -> &'static str {
56         "Vec<i32>"
57     }
58 }
59
60 impl Foo for String {
61     fn foo(&self) -> &'static str {
62         "String"
63     }
64 }
65
66 impl Foo for i32 {
67     fn foo(&self) -> &'static str {
68         "i32"
69     }
70 }
71
72 struct NotClone;
73
74 trait MyMarker {}
75 impl<T: Clone + MyMarker> Foo for T {
76     default fn foo(&self) -> &'static str {
77         "generic Clone + MyMarker"
78     }
79 }
80
81 #[derive(Clone)]
82 struct MarkedAndClone;
83 impl MyMarker for MarkedAndClone {}
84
85 fn  main() {
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");
98 }