]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/kindck-copy.rs
Auto merge of #22517 - brson:relnotes, r=Gankro
[rust.git] / 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.
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 #[derive(Copy)]
21 struct MyStruct {
22     x: isize,
23     y: isize,
24 }
25
26 struct MyNoncopyStruct {
27     x: Box<char>,
28 }
29
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]>();
36
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
40
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
46
47     // borrowed object types are generally ok
48     assert_copy::<&'a Dummy>();
49     assert_copy::<&'a (Dummy+Copy)>();
50     assert_copy::<&'static (Dummy+Copy)>();
51
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
55
56     // mutable object types are not ok
57     assert_copy::<&'a mut (Dummy+Copy)>();  //~ ERROR `core::marker::Copy` is not implemented
58
59     // unsafe ptrs are ok
60     assert_copy::<*const isize>();
61     assert_copy::<*const &'a mut isize>();
62
63     // regular old ints and such are ok
64     assert_copy::<isize>();
65     assert_copy::<bool>();
66     assert_copy::<()>();
67
68     // tuples are ok
69     assert_copy::<(isize,isize)>();
70
71     // structs of POD are ok
72     assert_copy::<MyStruct>();
73
74     // structs containing non-POD are not ok
75     assert_copy::<MyNoncopyStruct>(); //~ ERROR `core::marker::Copy` is not implemented
76
77     // ref counted types are not ok
78     assert_copy::<Rc<isize>>();   //~ ERROR `core::marker::Copy` is not implemented
79 }
80
81 pub fn main() {
82 }
83