]> git.lizzy.rs Git - rust.git/blob - tests/ui/derive.rs
Auto merge of #9174 - flip1995:rustup, r=Jarcho
[rust.git] / tests / ui / derive.rs
1 #![allow(dead_code)]
2 #![warn(clippy::expl_impl_clone_on_copy)]
3
4 #[derive(Copy)]
5 struct Qux;
6
7 impl Clone for Qux {
8     fn clone(&self) -> Self {
9         Qux
10     }
11 }
12
13 // looks like unions don't support deriving Clone for now
14 #[derive(Copy)]
15 union Union {
16     a: u8,
17 }
18
19 impl Clone for Union {
20     fn clone(&self) -> Self {
21         Union { a: 42 }
22     }
23 }
24
25 // See #666
26 #[derive(Copy)]
27 struct Lt<'a> {
28     a: &'a u8,
29 }
30
31 impl<'a> Clone for Lt<'a> {
32     fn clone(&self) -> Self {
33         unimplemented!()
34     }
35 }
36
37 #[derive(Copy)]
38 struct BigArray {
39     a: [u8; 65],
40 }
41
42 impl Clone for BigArray {
43     fn clone(&self) -> Self {
44         unimplemented!()
45     }
46 }
47
48 #[derive(Copy)]
49 struct FnPtr {
50     a: fn() -> !,
51 }
52
53 impl Clone for FnPtr {
54     fn clone(&self) -> Self {
55         unimplemented!()
56     }
57 }
58
59 // Ok, Clone trait impl doesn't have constrained generics.
60 #[derive(Copy)]
61 struct Generic<T> {
62     a: T,
63 }
64
65 impl<T> Clone for Generic<T> {
66     fn clone(&self) -> Self {
67         unimplemented!()
68     }
69 }
70
71 #[derive(Copy)]
72 struct Generic2<T>(T);
73 impl<T: Clone> Clone for Generic2<T> {
74     fn clone(&self) -> Self {
75         Self(self.0.clone())
76     }
77 }
78
79 // Ok, Clone trait impl doesn't have constrained generics.
80 #[derive(Copy)]
81 struct GenericRef<'a, T, U>(T, &'a U);
82 impl<T: Clone, U> Clone for GenericRef<'_, T, U> {
83     fn clone(&self) -> Self {
84         Self(self.0.clone(), self.1)
85     }
86 }
87
88 fn main() {}