]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/specialization/defaultimpl/specialization-cross-crate.rs
Auto merge of #41433 - estebank:constructor, r=michaelwoerister
[rust.git] / src / test / run-pass / specialization / defaultimpl / specialization-cross-crate.rs
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 // aux-build:specialization_cross_crate.rs
12
13 #![feature(specialization)]
14
15 extern crate specialization_cross_crate;
16
17 use specialization_cross_crate::*;
18
19 struct NotClone;
20
21 #[derive(Clone)]
22 struct MarkedAndClone;
23 impl MyMarker for MarkedAndClone {}
24
25 struct MyType<T>(T);
26 default impl<T> Foo for MyType<T> {
27     fn foo(&self) -> &'static str {
28         "generic MyType"
29     }
30 }
31
32 impl Foo for MyType<u8> {
33     fn foo(&self) -> &'static str {
34         "MyType<u8>"
35     }
36 }
37
38 struct MyOtherType;
39 impl Foo for MyOtherType {}
40
41 fn  main() {
42     assert!(NotClone.foo() == "generic");
43     assert!(0u8.foo() == "generic Clone");
44     assert!(vec![NotClone].foo() == "generic");
45     assert!(vec![0u8].foo() == "generic Vec");
46     assert!(vec![0i32].foo() == "Vec<i32>");
47     assert!(0i32.foo() == "i32");
48     assert!(String::new().foo() == "String");
49     assert!(((), 0).foo() == "generic pair");
50     assert!(((), ()).foo() == "generic uniform pair");
51     assert!((0u8, 0u32).foo() == "(u8, u32)");
52     assert!((0u8, 0u8).foo() == "(u8, u8)");
53     assert!(MarkedAndClone.foo() == "generic Clone + MyMarker");
54
55     assert!(MyType(()).foo() == "generic MyType");
56     assert!(MyType(0u8).foo() == "MyType<u8>");
57     assert!(MyOtherType.foo() == "generic");
58 }