]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/kindck-pod.rs
94902d4e68ea5a50d155453989f933282c2cef44
[rust.git] / src / test / compile-fail / kindck-pod.rs
1 // Copyright 2012 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 // Test which of the builtin types are considered POD.
12
13 #[feature(managed_boxes)];
14
15 use std::rc::Rc;
16
17 fn assert_pod<T:Pod>() { }
18 trait Dummy { }
19
20 struct MyStruct {
21     x: int,
22     y: int,
23 }
24
25 struct MyNonpodStruct {
26     x: ~int,
27 }
28
29 fn test<'a,T,U:Pod>(_: &'a int) {
30     // lifetime pointers are ok...
31     assert_pod::<&'static int>();
32     assert_pod::<&'a int>();
33     assert_pod::<&'a str>();
34     assert_pod::<&'a [int]>();
35
36     // ...unless they are mutable
37     assert_pod::<&'static mut int>(); //~ ERROR does not fulfill `Pod`
38     assert_pod::<&'a mut int>();  //~ ERROR does not fulfill `Pod`
39
40     // ~ pointers are not ok
41     assert_pod::<~int>();   //~ ERROR does not fulfill `Pod`
42     assert_pod::<~str>();   //~ ERROR does not fulfill `Pod`
43     assert_pod::<Vec<int> >(); //~ ERROR does not fulfill `Pod`
44     assert_pod::<~&'a mut int>(); //~ ERROR does not fulfill `Pod`
45
46     // borrowed object types are generally ok
47     assert_pod::<&'a Dummy>();
48     assert_pod::<&'a Dummy:Pod>();
49     assert_pod::<&'static Dummy:Pod>();
50
51     // owned object types are not ok
52     assert_pod::<~Dummy>(); //~ ERROR does not fulfill `Pod`
53     assert_pod::<~Dummy:Pod>(); //~ ERROR does not fulfill `Pod`
54
55     // mutable object types are not ok
56     assert_pod::<&'a mut Dummy:Pod>();  //~ ERROR does not fulfill `Pod`
57
58     // closures are like an `&mut` object
59     assert_pod::<||>(); //~ ERROR does not fulfill `Pod`
60
61     // unsafe ptrs are ok
62     assert_pod::<*int>();
63     assert_pod::<*&'a mut int>();
64
65     // regular old ints and such are ok
66     assert_pod::<int>();
67     assert_pod::<bool>();
68     assert_pod::<()>();
69
70     // tuples are ok
71     assert_pod::<(int,int)>();
72
73     // structs of POD are ok
74     assert_pod::<MyStruct>();
75
76     // structs containing non-POD are not ok
77     assert_pod::<MyNonpodStruct>(); //~ ERROR does not fulfill `Pod`
78
79     // managed or ref counted types are not ok
80     assert_pod::<@int>();   //~ ERROR does not fulfill `Pod`
81     assert_pod::<Rc<int>>();   //~ ERROR does not fulfill `Pod`
82 }
83
84 pub fn main() {
85 }
86