]> git.lizzy.rs Git - rust.git/blob - src/test/ui/kindck/kindck-copy.rs
Compress amount of hashed bytes for `isize` values in StableHasher
[rust.git] / src / test / ui / kindck / kindck-copy.rs
1 // Test which of the builtin types are considered POD.
2
3 use std::rc::Rc;
4
5 fn assert_copy<T:Copy>() { }
6
7 trait Dummy { }
8
9 #[derive(Copy, Clone)]
10 struct MyStruct {
11     x: isize,
12     y: isize,
13 }
14
15 struct MyNoncopyStruct {
16     x: Box<char>,
17 }
18
19 fn test<'a,T,U:Copy>(_: &'a isize) {
20     // lifetime pointers are ok...
21     assert_copy::<&'static isize>();
22     assert_copy::<&'a isize>();
23     assert_copy::<&'a str>();
24     assert_copy::<&'a [isize]>();
25
26     // ...unless they are mutable
27     assert_copy::<&'static mut isize>(); //~ ERROR : Copy` is not satisfied
28     assert_copy::<&'a mut isize>();  //~ ERROR : Copy` is not satisfied
29
30     // boxes are not ok
31     assert_copy::<Box<isize>>();   //~ ERROR : Copy` is not satisfied
32     assert_copy::<String>();   //~ ERROR : Copy` is not satisfied
33     assert_copy::<Vec<isize> >(); //~ ERROR : Copy` is not satisfied
34     assert_copy::<Box<&'a mut isize>>(); //~ ERROR : Copy` is not satisfied
35
36     // borrowed object types are generally ok
37     assert_copy::<&'a dyn Dummy>();
38     assert_copy::<&'a (dyn Dummy + Send)>();
39     assert_copy::<&'static (dyn Dummy + Send)>();
40
41     // owned object types are not ok
42     assert_copy::<Box<dyn Dummy>>(); //~ ERROR : Copy` is not satisfied
43     assert_copy::<Box<dyn Dummy + Send>>(); //~ ERROR : Copy` is not satisfied
44
45     // mutable object types are not ok
46     assert_copy::<&'a mut (dyn Dummy + Send)>();  //~ ERROR : Copy` is not satisfied
47
48     // unsafe ptrs are ok
49     assert_copy::<*const isize>();
50     assert_copy::<*const &'a mut isize>();
51
52     // regular old ints and such are ok
53     assert_copy::<isize>();
54     assert_copy::<bool>();
55     assert_copy::<()>();
56
57     // tuples are ok
58     assert_copy::<(isize,isize)>();
59
60     // structs of POD are ok
61     assert_copy::<MyStruct>();
62
63     // structs containing non-POD are not ok
64     assert_copy::<MyNoncopyStruct>(); //~ ERROR : Copy` is not satisfied
65
66     // ref counted types are not ok
67     assert_copy::<Rc<isize>>();   //~ ERROR : Copy` is not satisfied
68 }
69
70 pub fn main() {
71 }