1 #![feature(untagged_unions)]
2 #![allow(dead_code)]
3 #![warn(clippy::expl_impl_clone_on_copy)]
4 
5 #[derive(Copy)]
6 struct Qux;
7 
8 impl Clone for Qux {
clone(&self) -> Self9     fn clone(&self) -> Self {
10         Qux
11     }
12 }
13 
14 // looks like unions don't support deriving Clone for now
15 #[derive(Copy)]
16 union Union {
17     a: u8,
18 }
19 
20 impl Clone for Union {
clone(&self) -> Self21     fn clone(&self) -> Self {
22         Union { a: 42 }
23     }
24 }
25 
26 // See #666
27 #[derive(Copy)]
28 struct Lt<'a> {
29     a: &'a u8,
30 }
31 
32 impl<'a> Clone for Lt<'a> {
clone(&self) -> Self33     fn clone(&self) -> Self {
34         unimplemented!()
35     }
36 }
37 
38 #[derive(Copy)]
39 struct BigArray {
40     a: [u8; 65],
41 }
42 
43 impl Clone for BigArray {
clone(&self) -> Self44     fn clone(&self) -> Self {
45         unimplemented!()
46     }
47 }
48 
49 #[derive(Copy)]
50 struct FnPtr {
51     a: fn() -> !,
52 }
53 
54 impl Clone for FnPtr {
clone(&self) -> Self55     fn clone(&self) -> Self {
56         unimplemented!()
57     }
58 }
59 
60 // Ok, Clone trait impl doesn't have constrained generics.
61 #[derive(Copy)]
62 struct Generic<T> {
63     a: T,
64 }
65 
66 impl<T> Clone for Generic<T> {
clone(&self) -> Self67     fn clone(&self) -> Self {
68         unimplemented!()
69     }
70 }
71 
72 #[derive(Copy)]
73 struct Generic2<T>(T);
74 impl<T: Clone> Clone for Generic2<T> {
clone(&self) -> Self75     fn clone(&self) -> Self {
76         Self(self.0.clone())
77     }
78 }
79 
80 // Ok, Clone trait impl doesn't have constrained generics.
81 #[derive(Copy)]
82 struct GenericRef<'a, T, U>(T, &'a U);
83 impl<T: Clone, U> Clone for GenericRef<'_, T, U> {
clone(&self) -> Self84     fn clone(&self) -> Self {
85         Self(self.0.clone(), self.1)
86     }
87 }
88 
main()89 fn main() {}
90