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