]> git.lizzy.rs Git - rust.git/blob - src/test/ui/specialization/specialization-cross-crate.rs
fa63c86632985ae3c37e90dd67a0f6d6fc25c779
[rust.git] / src / test / ui / specialization / specialization-cross-crate.rs
1 // run-pass
2
3 // aux-build:specialization_cross_crate.rs
4
5 #![feature(specialization)]
6
7 extern crate specialization_cross_crate;
8
9 use specialization_cross_crate::*;
10
11 struct NotClone;
12
13 #[derive(Clone)]
14 struct MarkedAndClone;
15 impl MyMarker for MarkedAndClone {}
16
17 struct MyType<T>(T);
18 impl<T> Foo for MyType<T> {
19     default fn foo(&self) -> &'static str {
20         "generic MyType"
21     }
22 }
23
24 impl Foo for MyType<u8> {
25     fn foo(&self) -> &'static str {
26         "MyType<u8>"
27     }
28 }
29
30 struct MyOtherType;
31 impl Foo for MyOtherType {}
32
33 fn  main() {
34     assert!(NotClone.foo() == "generic");
35     assert!(0u8.foo() == "generic Clone");
36     assert!(vec![NotClone].foo() == "generic");
37     assert!(vec![0u8].foo() == "generic Vec");
38     assert!(vec![0i32].foo() == "Vec<i32>");
39     assert!(0i32.foo() == "i32");
40     assert!(String::new().foo() == "String");
41     assert!(((), 0).foo() == "generic pair");
42     assert!(((), ()).foo() == "generic uniform pair");
43     assert!((0u8, 0u32).foo() == "(u8, u32)");
44     assert!((0u8, 0u8).foo() == "(u8, u8)");
45     assert!(MarkedAndClone.foo() == "generic Clone + MyMarker");
46
47     assert!(MyType(()).foo() == "generic MyType");
48     assert!(MyType(0u8).foo() == "MyType<u8>");
49     assert!(MyOtherType.foo() == "generic");
50 }