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.
16 fn assert_copy<T:Copy>() { }
26 struct MyNoncopyStruct {
30 fn test<'a,T,U:Copy>(_: &'a isize) {
31 // lifetime pointers are ok...
32 assert_copy::<&'static isize>();
33 assert_copy::<&'a isize>();
34 assert_copy::<&'a str>();
35 assert_copy::<&'a [isize]>();
37 // ...unless they are mutable
38 assert_copy::<&'static mut isize>(); //~ ERROR `core::marker::Copy` is not implemented
39 assert_copy::<&'a mut isize>(); //~ ERROR `core::marker::Copy` is not implemented
41 // ~ pointers are not ok
42 assert_copy::<Box<isize>>(); //~ ERROR `core::marker::Copy` is not implemented
43 assert_copy::<String>(); //~ ERROR `core::marker::Copy` is not implemented
44 assert_copy::<Vec<isize> >(); //~ ERROR `core::marker::Copy` is not implemented
45 assert_copy::<Box<&'a mut isize>>(); //~ ERROR `core::marker::Copy` is not implemented
47 // borrowed object types are generally ok
48 assert_copy::<&'a Dummy>();
49 assert_copy::<&'a (Dummy+Copy)>();
50 assert_copy::<&'static (Dummy+Copy)>();
52 // owned object types are not ok
53 assert_copy::<Box<Dummy>>(); //~ ERROR `core::marker::Copy` is not implemented
54 assert_copy::<Box<Dummy+Copy>>(); //~ ERROR `core::marker::Copy` is not implemented
56 // mutable object types are not ok
57 assert_copy::<&'a mut (Dummy+Copy)>(); //~ ERROR `core::marker::Copy` is not implemented
60 assert_copy::<*const isize>();
61 assert_copy::<*const &'a mut isize>();
63 // regular old ints and such are ok
64 assert_copy::<isize>();
65 assert_copy::<bool>();
69 assert_copy::<(isize,isize)>();
71 // structs of POD are ok
72 assert_copy::<MyStruct>();
74 // structs containing non-POD are not ok
75 assert_copy::<MyNoncopyStruct>(); //~ ERROR `core::marker::Copy` is not implemented
77 // ref counted types are not ok
78 assert_copy::<Rc<isize>>(); //~ ERROR `core::marker::Copy` is not implemented