Skip to content

Commit 397e975

Browse files
Use derives on CanonAbi
1 parent 9212ced commit 397e975

File tree

1 file changed

+9
-47
lines changed

1 file changed

+9
-47
lines changed

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
21
use std::fmt;
3-
use std::hash::{Hash, Hasher};
42

53
#[cfg(feature = "nightly")]
6-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd};
4+
use rustc_macros::HashStable_Generic;
75

86
use crate::ExternAbi;
97

@@ -19,6 +17,8 @@ use crate::ExternAbi;
1917
/// In that sense, this erases mere syntactic distinctions to create a canonical *directive*,
2018
/// rather than picking the "actual" ABI.
2119
#[derive(Copy, Clone, Debug)]
20+
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
21+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
2222
pub enum CanonAbi {
2323
// NOTE: the use of nested variants for some ABIs is for many targets they don't matter,
2424
// and this pushes the complexity of their reasoning to target-specific code,
@@ -48,50 +48,6 @@ pub enum CanonAbi {
4848
X86(X86Call),
4949
}
5050

51-
// For most "utility" impls, just forward CanonAbi to ExternAbi as it is notionally a subset
52-
impl Ord for CanonAbi {
53-
fn cmp(&self, other: &Self) -> Ordering {
54-
self.to_erased_extern_abi().cmp(&other.to_erased_extern_abi())
55-
}
56-
}
57-
58-
impl PartialOrd for CanonAbi {
59-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
60-
Some(self.cmp(&other))
61-
}
62-
}
63-
64-
impl PartialEq for CanonAbi {
65-
fn eq(&self, other: &Self) -> bool {
66-
self.cmp(&other) == Ordering::Equal
67-
}
68-
}
69-
70-
impl Eq for CanonAbi {}
71-
72-
impl Hash for CanonAbi {
73-
fn hash<H: Hasher>(&self, state: &mut H) {
74-
self.to_erased_extern_abi().hash(state)
75-
}
76-
}
77-
78-
// because we forward hashing to ExternAbi, also forward this:
79-
#[cfg(feature = "nightly")]
80-
impl<C> HashStable<C> for CanonAbi {
81-
#[inline]
82-
fn hash_stable(&self, _: &mut C, hasher: &mut StableHasher) {
83-
Hash::hash(self, hasher);
84-
}
85-
}
86-
87-
#[cfg(feature = "nightly")]
88-
impl StableOrd for CanonAbi {
89-
const CAN_USE_UNSTABLE_SORT: bool = true;
90-
91-
// because each ABI is hashed like a string, there is no possible instability
92-
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
93-
}
94-
9551
impl fmt::Display for CanonAbi {
9652
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9753
self.to_erased_extern_abi().fmt(f)
@@ -141,6 +97,8 @@ impl CanonAbi {
14197
/// these "ABI" differences are not relevant to callers, since there is "no caller".
14298
/// These only affect callee codegen. making their categorization as distinct ABIs a bit peculiar.
14399
#[derive(Copy, Clone, Debug)]
100+
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
101+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
144102
pub enum InterruptKind {
145103
Avr,
146104
AvrNonBlocking,
@@ -154,6 +112,8 @@ pub enum InterruptKind {
154112
///
155113
/// One of SysV64 or Win64 may alias the C ABI, and arguably Win64 is cross-platform now?
156114
#[derive(Clone, Copy, Debug)]
115+
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
116+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
157117
pub enum X86Call {
158118
/// "fastcall" has both GNU and Windows variants
159119
Fastcall,
@@ -167,6 +127,8 @@ pub enum X86Call {
167127

168128
/// ABIs defined for 32-bit Arm
169129
#[derive(Copy, Clone, Debug)]
130+
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
131+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
170132
pub enum ArmCall {
171133
Aapcs,
172134
CCmseNonSecureCall,

0 commit comments

Comments
 (0)