]>
git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/kindck-copy.rs
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.
15 fn assert_copy
<T
:Copy
>() { }
19 #[derive(Copy, Clone)]
25 struct MyNoncopyStruct
{
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]>();
36 // ...unless they are mutable
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
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
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
::<Box
<Dummy
>>(); //~ ERROR : std::marker::Copy` is not satisfied
53 assert_copy
::<Box
<Dummy
+Copy
>>(); //~ ERROR : std::marker::Copy` is not satisfied
55 // mutable object types are not ok
56 assert_copy
::<&'a
mut (Dummy
+Copy
)>(); //~ ERROR : std::marker::Copy` is not satisfied
59 assert_copy
::<*const isize>();
60 assert_copy
::<*const &'a
mut isize>();
62 // regular old ints and such are ok
63 assert_copy
::<isize>();
64 assert_copy
::<bool
>();
68 assert_copy
::<(isize,isize)>();
70 // structs of POD are ok
71 assert_copy
::<MyStruct
>();
73 // structs containing non-POD are not ok
74 assert_copy
::<MyNoncopyStruct
>(); //~ ERROR : std::marker::Copy` is not satisfied
76 // ref counted types are not ok
77 assert_copy
::<Rc
<isize>>(); //~ ERROR : std::marker::Copy` is not satisfied