]> git.lizzy.rs Git - rust.git/blob - src/test/ui/kindck/kindck-copy.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / kindck / 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 use std::rc::Rc;
14
15 fn assert_copy<T:Copy>() { }
16
17 trait Dummy { }
18
19 #[derive(Copy, Clone)]
20 struct MyStruct {
21     x: isize,
22     y: isize,
23 }
24
25 struct MyNoncopyStruct {
26     x: Box<char>,
27 }
28
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]>();
35
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
39
40     // boxes are not ok
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
45
46     // borrowed object types are generally ok
47     assert_copy::<&'a Dummy>();
48     assert_copy::<&'a (Dummy+Send)>();
49     assert_copy::<&'static (Dummy+Send)>();
50
51     // owned object types are not ok
52     assert_copy::<Box<Dummy>>(); //~ ERROR : std::marker::Copy` is not satisfied
53     assert_copy::<Box<Dummy+Send>>(); //~ ERROR : std::marker::Copy` is not satisfied
54
55     // mutable object types are not ok
56     assert_copy::<&'a mut (Dummy+Send)>();  //~ ERROR : std::marker::Copy` is not satisfied
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 : std::marker::Copy` is not satisfied
75
76     // ref counted types are not ok
77     assert_copy::<Rc<isize>>();   //~ ERROR : std::marker::Copy` is not satisfied
78 }
79
80 pub fn main() {
81 }