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)];
18 fn assert_pod<T:Pod>() { }
26 struct MyNonpodStruct {
30 fn test<'a,T,U:Pod>(_: &'a int) {
31 // lifetime pointers are ok...
32 assert_pod::<&'static int>();
33 assert_pod::<&'a int>();
34 assert_pod::<&'a str>();
35 assert_pod::<&'a [int]>();
37 // ...unless they are mutable
38 assert_pod::<&'static mut int>(); //~ ERROR does not fulfill `Pod`
39 assert_pod::<&'a mut int>(); //~ ERROR does not fulfill `Pod`
41 // ~ pointers are not ok
42 assert_pod::<~int>(); //~ ERROR does not fulfill `Pod`
43 assert_pod::<~str>(); //~ ERROR does not fulfill `Pod`
44 assert_pod::<Vec<int> >(); //~ ERROR does not fulfill `Pod`
45 assert_pod::<~&'a mut int>(); //~ ERROR does not fulfill `Pod`
47 // borrowed object types are generally ok
48 assert_pod::<&'a Dummy>();
49 assert_pod::<&'a Dummy:Pod>();
50 assert_pod::<&'static Dummy:Pod>();
52 // owned object types are not ok
53 assert_pod::<~Dummy>(); //~ ERROR does not fulfill `Pod`
54 assert_pod::<~Dummy:Pod>(); //~ ERROR does not fulfill `Pod`
56 // mutable object types are not ok
57 assert_pod::<&'a mut Dummy:Pod>(); //~ ERROR does not fulfill `Pod`
59 // closures are like an `&mut` object
60 assert_pod::<||>(); //~ ERROR does not fulfill `Pod`
64 assert_pod::<*&'a mut int>();
66 // regular old ints and such are ok
72 assert_pod::<(int,int)>();
74 // structs of POD are ok
75 assert_pod::<MyStruct>();
77 // structs containing non-POD are not ok
78 assert_pod::<MyNonpodStruct>(); //~ ERROR does not fulfill `Pod`
80 // managed or ref counted types are not ok
81 assert_pod::<@int>(); //~ ERROR does not fulfill `Pod`
82 assert_pod::<Rc<int>>(); //~ ERROR does not fulfill `Pod`