1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use ConstParamTy_;
use Freeze;
/// # Safety
///
/// You may only implement this trait for a type if it meets all of the following conditions:
/// 1. This type must not be a union, pointer, or reference.
/// 2. Condition #1 must hold recursively for this types fields or variants (if it has any).
/// 3. This types [`PartialEq`] impl must be equivalent to bytewise comparing all non-padding bytes of the data.
///
/// If the type fails to meet any one of these, implementing this trait is considered to be UB.
///
/// # How to implement this trait
///
/// The easiest and recommended way to argue that the implementation of this trait is safe is to ensure:
///
/// 1. All of the types fields or variants (if it has any) implement [`SureEq`].
/// 2. Use the `std` derive macros, namely `#[derive(PartialEq, Eq)]` to derive [`PartialEq`] and [`Eq`]
///
/// (FIXME: the above doesn't account for the fact that this wouldn't make the `Eq` impl `const`).
///
/// If these conditions are fulfilled, this is sufficient to argue that the 3 required preconditions are followed.
pub unsafe
// SAFETY:
// For the primitives below, these are the reasons why each required condition is satisfied.
// #1 Because this is a primitive type that is not any of union, pointer, or reference.
// #2 Because this is a primitive type without any fields or variants.
// #3 Because we trust `std` to have a `PartialEq` implementation that is equivalent to this requirement.
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: see above
unsafe
// SAFETY: TODO
unsafe
;
}
// implementations for tuples up to length 12, because that is as far as std goes for ConstParamTy_
unsafe_impl_sure_eq_for_tuples!