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.
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.
11 // Test which of the builtin types are considered POD.
13 #[feature(managed_boxes)];
17 fn assert_pod<T:Pod>() { }
25 struct MyNonpodStruct {
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]>();
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`
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`
46 // borrowed object types are generally ok
47 assert_pod::<&'a Dummy>();
48 assert_pod::<&'a Dummy:Pod>();
49 assert_pod::<&'static Dummy:Pod>();
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`
55 // mutable object types are not ok
56 assert_pod::<&'a mut Dummy:Pod>(); //~ ERROR does not fulfill `Pod`
58 // closures are like an `&mut` object
59 assert_pod::<||>(); //~ ERROR does not fulfill `Pod`
63 assert_pod::<*&'a mut int>();
65 // regular old ints and such are ok
71 assert_pod::<(int,int)>();
73 // structs of POD are ok
74 assert_pod::<MyStruct>();
76 // structs containing non-POD are not ok
77 assert_pod::<MyNonpodStruct>(); //~ ERROR does not fulfill `Pod`
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`