]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | ||
1a4d82fc JJ |
13 | use std::rc::Rc; |
14 | ||
15 | fn assert_copy<T:Copy>() { } | |
16 | ||
9346a6ac | 17 | trait Dummy { } |
1a4d82fc | 18 | |
c34b1796 | 19 | #[derive(Copy, Clone)] |
1a4d82fc JJ |
20 | struct MyStruct { |
21 | x: isize, | |
22 | y: isize, | |
23 | } | |
24 | ||
1a4d82fc JJ |
25 | struct MyNoncopyStruct { |
26 | x: Box<char>, | |
27 | } | |
28 | ||
29 | fn test<'a,T,U:Copy>(_: &'a isize) { | |
30 | // lifetime pointers are ok... | |
31 | assert_copy::<&'static isize>(); | |
32 | assert_copy::<&'a isize>(); | |
33 | assert_copy::<&'a str>(); | |
34 | assert_copy::<&'a [isize]>(); | |
35 | ||
36 | // ...unless they are mutable | |
54a0048b SL |
37 | assert_copy::<&'static mut isize>(); //~ ERROR : std::marker::Copy` is not satisfied |
38 | assert_copy::<&'a mut isize>(); //~ ERROR : std::marker::Copy` is not satisfied | |
1a4d82fc | 39 | |
62682a34 | 40 | // boxes are not ok |
54a0048b SL |
41 | assert_copy::<Box<isize>>(); //~ ERROR : std::marker::Copy` is not satisfied |
42 | assert_copy::<String>(); //~ ERROR : std::marker::Copy` is not satisfied | |
43 | assert_copy::<Vec<isize> >(); //~ ERROR : std::marker::Copy` is not satisfied | |
44 | assert_copy::<Box<&'a mut isize>>(); //~ ERROR : std::marker::Copy` is not satisfied | |
1a4d82fc JJ |
45 | |
46 | // borrowed object types are generally ok | |
47 | assert_copy::<&'a Dummy>(); | |
48 | assert_copy::<&'a (Dummy+Copy)>(); | |
49 | assert_copy::<&'static (Dummy+Copy)>(); | |
50 | ||
51 | // owned object types are not ok | |
54a0048b SL |
52 | assert_copy::<Box<Dummy>>(); //~ ERROR : std::marker::Copy` is not satisfied |
53 | assert_copy::<Box<Dummy+Copy>>(); //~ ERROR : std::marker::Copy` is not satisfied | |
1a4d82fc JJ |
54 | |
55 | // mutable object types are not ok | |
54a0048b | 56 | assert_copy::<&'a mut (Dummy+Copy)>(); //~ ERROR : std::marker::Copy` is not satisfied |
1a4d82fc JJ |
57 | |
58 | // unsafe ptrs are ok | |
59 | assert_copy::<*const isize>(); | |
60 | assert_copy::<*const &'a mut isize>(); | |
61 | ||
62 | // regular old ints and such are ok | |
63 | assert_copy::<isize>(); | |
64 | assert_copy::<bool>(); | |
65 | assert_copy::<()>(); | |
66 | ||
67 | // tuples are ok | |
68 | assert_copy::<(isize,isize)>(); | |
69 | ||
70 | // structs of POD are ok | |
71 | assert_copy::<MyStruct>(); | |
72 | ||
73 | // structs containing non-POD are not ok | |
54a0048b | 74 | assert_copy::<MyNoncopyStruct>(); //~ ERROR : std::marker::Copy` is not satisfied |
1a4d82fc JJ |
75 | |
76 | // ref counted types are not ok | |
54a0048b | 77 | assert_copy::<Rc<isize>>(); //~ ERROR : std::marker::Copy` is not satisfied |
1a4d82fc JJ |
78 | } |
79 | ||
80 | pub fn main() { | |
81 | } |