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_copy<T:Copy>() { }
25 struct MyNoncopyStruct {
29 fn test<'a,T,U:Copy>(_: &'a int) {
30 // lifetime pointers are ok...
31 assert_copy::<&'static int>();
32 assert_copy::<&'a int>();
33 assert_copy::<&'a str>();
34 assert_copy::<&'a [int]>();
36 // ...unless they are mutable
37 assert_copy::<&'static mut int>(); //~ ERROR does not fulfill
38 assert_copy::<&'a mut int>(); //~ ERROR does not fulfill
40 // ~ pointers are not ok
41 assert_copy::<~int>(); //~ ERROR does not fulfill
42 assert_copy::<~str>(); //~ ERROR does not fulfill
43 assert_copy::<Vec<int> >(); //~ ERROR does not fulfill
44 assert_copy::<~&'a mut int>(); //~ ERROR does not fulfill
46 // borrowed object types are generally ok
47 assert_copy::<&'a Dummy>();
48 assert_copy::<&'a Dummy:Copy>();
49 assert_copy::<&'static Dummy:Copy>();
51 // owned object types are not ok
52 assert_copy::<~Dummy>(); //~ ERROR does not fulfill
53 assert_copy::<~Dummy:Copy>(); //~ ERROR does not fulfill
55 // mutable object types are not ok
56 assert_copy::<&'a mut Dummy:Copy>(); //~ ERROR does not fulfill
58 // closures are like an `&mut` object
59 assert_copy::<||>(); //~ ERROR does not fulfill
62 assert_copy::<*int>();
63 assert_copy::<*&'a mut int>();
65 // regular old ints and such are ok
67 assert_copy::<bool>();
71 assert_copy::<(int,int)>();
73 // structs of POD are ok
74 assert_copy::<MyStruct>();
76 // structs containing non-POD are not ok
77 assert_copy::<MyNoncopyStruct>(); //~ ERROR does not fulfill
79 // managed or ref counted types are not ok
80 assert_copy::<@int>(); //~ ERROR does not fulfill
81 assert_copy::<Rc<int>>(); //~ ERROR does not fulfill