]> git.lizzy.rs Git - rust.git/blob - tests/ui/derive.rs
Merge branch 'master' into add-lints-aseert-checks
[rust.git] / tests / ui / derive.rs
1 #![feature(untagged_unions)]
2 #![allow(dead_code)]
3 #![warn(clippy::expl_impl_clone_on_copy)]
4
5 use std::hash::{Hash, Hasher};
6
7 #[derive(PartialEq, Hash)]
8 struct Foo;
9
10 impl PartialEq<u64> for Foo {
11     fn eq(&self, _: &u64) -> bool {
12         true
13     }
14 }
15
16 #[derive(Hash)]
17 struct Bar;
18
19 impl PartialEq for Bar {
20     fn eq(&self, _: &Bar) -> bool {
21         true
22     }
23 }
24
25 #[derive(Hash)]
26 struct Baz;
27
28 impl PartialEq<Baz> for Baz {
29     fn eq(&self, _: &Baz) -> bool {
30         true
31     }
32 }
33
34 #[derive(PartialEq)]
35 struct Bah;
36
37 impl Hash for Bah {
38     fn hash<H: Hasher>(&self, _: &mut H) {}
39 }
40
41 #[derive(Copy)]
42 struct Qux;
43
44 impl Clone for Qux {
45     fn clone(&self) -> Self {
46         Qux
47     }
48 }
49
50 // looks like unions don't support deriving Clone for now
51 #[derive(Copy)]
52 union Union {
53     a: u8,
54 }
55
56 impl Clone for Union {
57     fn clone(&self) -> Self {
58         Union { a: 42 }
59     }
60 }
61
62 // See #666
63 #[derive(Copy)]
64 struct Lt<'a> {
65     a: &'a u8,
66 }
67
68 impl<'a> Clone for Lt<'a> {
69     fn clone(&self) -> Self {
70         unimplemented!()
71     }
72 }
73
74 // Ok, `Clone` cannot be derived because of the big array
75 #[derive(Copy)]
76 struct BigArray {
77     a: [u8; 65],
78 }
79
80 impl Clone for BigArray {
81     fn clone(&self) -> Self {
82         unimplemented!()
83     }
84 }
85
86 // Ok, function pointers are not always Clone
87 #[derive(Copy)]
88 struct FnPtr {
89     a: fn() -> !,
90 }
91
92 impl Clone for FnPtr {
93     fn clone(&self) -> Self {
94         unimplemented!()
95     }
96 }
97
98 // Ok, generics
99 #[derive(Copy)]
100 struct Generic<T> {
101     a: T,
102 }
103
104 impl<T> Clone for Generic<T> {
105     fn clone(&self) -> Self {
106         unimplemented!()
107     }
108 }
109
110 fn main() {}