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