]> git.lizzy.rs Git - rust.git/blob - tests/ui/derive.rs
Merge branch 'master' into rustfmt_tests
[rust.git] / tests / ui / derive.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![feature(untagged_unions)]
11 #![allow(dead_code)]
12 #![warn(clippy::expl_impl_clone_on_copy)]
13
14 use std::hash::{Hash, Hasher};
15
16 #[derive(PartialEq, Hash)]
17 struct Foo;
18
19 impl PartialEq<u64> for Foo {
20     fn eq(&self, _: &u64) -> bool {
21         true
22     }
23 }
24
25 #[derive(Hash)]
26 struct Bar;
27
28 impl PartialEq for Bar {
29     fn eq(&self, _: &Bar) -> bool {
30         true
31     }
32 }
33
34 #[derive(Hash)]
35 struct Baz;
36
37 impl PartialEq<Baz> for Baz {
38     fn eq(&self, _: &Baz) -> bool {
39         true
40     }
41 }
42
43 #[derive(PartialEq)]
44 struct Bah;
45
46 impl Hash for Bah {
47     fn hash<H: Hasher>(&self, _: &mut H) {}
48 }
49
50 #[derive(Copy)]
51 struct Qux;
52
53 impl Clone for Qux {
54     fn clone(&self) -> Self {
55         Qux
56     }
57 }
58
59 // looks like unions don't support deriving Clone for now
60 #[derive(Copy)]
61 union Union {
62     a: u8,
63 }
64
65 impl Clone for Union {
66     fn clone(&self) -> Self {
67         Union { a: 42 }
68     }
69 }
70
71 // See #666
72 #[derive(Copy)]
73 struct Lt<'a> {
74     a: &'a u8,
75 }
76
77 impl<'a> Clone for Lt<'a> {
78     fn clone(&self) -> Self {
79         unimplemented!()
80     }
81 }
82
83 // Ok, `Clone` cannot be derived because of the big array
84 #[derive(Copy)]
85 struct BigArray {
86     a: [u8; 65],
87 }
88
89 impl Clone for BigArray {
90     fn clone(&self) -> Self {
91         unimplemented!()
92     }
93 }
94
95 // Ok, function pointers are not always Clone
96 #[derive(Copy)]
97 struct FnPtr {
98     a: fn() -> !,
99 }
100
101 impl Clone for FnPtr {
102     fn clone(&self) -> Self {
103         unimplemented!()
104     }
105 }
106
107 // Ok, generics
108 #[derive(Copy)]
109 struct Generic<T> {
110     a: T,
111 }
112
113 impl<T> Clone for Generic<T> {
114     fn clone(&self) -> Self {
115         unimplemented!()
116     }
117 }
118
119 fn main() {}