]> git.lizzy.rs Git - rust.git/blob - src/test/ui/derives/deriving-copyclone.rs
Auto merge of #106025 - matthiaskrgr:rollup-vz5rqah, r=matthiaskrgr
[rust.git] / src / test / ui / derives / deriving-copyclone.rs
1 // this will get a no-op Clone impl
2 #[derive(Copy, Clone)]
3 struct A {
4     a: i32,
5     b: i64
6 }
7
8 // this will get a deep Clone impl
9 #[derive(Copy, Clone)]
10 struct B<T> {
11     a: i32,
12     b: T
13 }
14
15 struct C; // not Copy or Clone
16 #[derive(Clone)] struct D; // Clone but not Copy
17
18 fn is_copy<T: Copy>(_: T) {}
19 fn is_clone<T: Clone>(_: T) {}
20
21 fn main() {
22     // A can be copied and cloned
23     is_copy(A { a: 1, b: 2 });
24     is_clone(A { a: 1, b: 2 });
25
26     // B<i32> can be copied and cloned
27     is_copy(B { a: 1, b: 2 });
28     is_clone(B { a: 1, b: 2 });
29
30     // B<C> cannot be copied or cloned
31     is_copy(B { a: 1, b: C }); //~ ERROR Copy
32     is_clone(B { a: 1, b: C }); //~ ERROR Clone
33
34     // B<D> can be cloned but not copied
35     is_copy(B { a: 1, b: D }); //~ ERROR Copy
36     is_clone(B { a: 1, b: D });
37 }