]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/kindck-copy.rs
Imported Upstream version 1.1.0+dfsg1
[rustc.git] / src / test / compile-fail / kindck-copy.rs
CommitLineData
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
13use std::rc::Rc;
14
15fn assert_copy<T:Copy>() { }
16
9346a6ac 17trait Dummy { }
1a4d82fc 18
c34b1796 19#[derive(Copy, Clone)]
1a4d82fc
JJ
20struct MyStruct {
21 x: isize,
22 y: isize,
23}
24
1a4d82fc
JJ
25struct MyNoncopyStruct {
26 x: Box<char>,
27}
28
29fn 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
37 assert_copy::<&'static mut isize>(); //~ ERROR `core::marker::Copy` is not implemented
38 assert_copy::<&'a mut isize>(); //~ ERROR `core::marker::Copy` is not implemented
39
d9579d0f 40 // owned pointers are not ok
1a4d82fc
JJ
41 assert_copy::<Box<isize>>(); //~ ERROR `core::marker::Copy` is not implemented
42 assert_copy::<String>(); //~ ERROR `core::marker::Copy` is not implemented
43 assert_copy::<Vec<isize> >(); //~ ERROR `core::marker::Copy` is not implemented
44 assert_copy::<Box<&'a mut isize>>(); //~ ERROR `core::marker::Copy` is not implemented
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
52 assert_copy::<Box<Dummy>>(); //~ ERROR `core::marker::Copy` is not implemented
53 assert_copy::<Box<Dummy+Copy>>(); //~ ERROR `core::marker::Copy` is not implemented
54
55 // mutable object types are not ok
56 assert_copy::<&'a mut (Dummy+Copy)>(); //~ ERROR `core::marker::Copy` is not implemented
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
74 assert_copy::<MyNoncopyStruct>(); //~ ERROR `core::marker::Copy` is not implemented
75
76 // ref counted types are not ok
77 assert_copy::<Rc<isize>>(); //~ ERROR `core::marker::Copy` is not implemented
78}
79
80pub fn main() {
81}