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