summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_span/src/def_id.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--compiler/rustc_span/src/def_id.rs35
1 files changed, 32 insertions, 3 deletions
diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs
index a1533fe46..bbeabdb55 100644
--- a/compiler/rustc_span/src/def_id.rs
+++ b/compiler/rustc_span/src/def_id.rs
@@ -218,7 +218,9 @@ impl<D: Decoder> Decodable<D> for DefIndex {
/// index and a def index.
///
/// You can create a `DefId` from a `LocalDefId` using `local_def_id.to_def_id()`.
-#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Copy)]
+#[derive(Clone, PartialEq, Eq, Copy)]
+// Don't derive order on 64-bit big-endian, so we can be consistent regardless of field order.
+#[cfg_attr(not(all(target_pointer_width = "64", target_endian = "big")), derive(PartialOrd, Ord))]
// On below-64 bit systems we can simply use the derived `Hash` impl
#[cfg_attr(not(target_pointer_width = "64"), derive(Hash))]
#[repr(C)]
@@ -260,6 +262,22 @@ impl Hash for DefId {
}
}
+// Implement the same comparison as derived with the other field order.
+#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
+impl Ord for DefId {
+ #[inline]
+ fn cmp(&self, other: &DefId) -> std::cmp::Ordering {
+ Ord::cmp(&(self.index, self.krate), &(other.index, other.krate))
+ }
+}
+#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
+impl PartialOrd for DefId {
+ #[inline]
+ fn partial_cmp(&self, other: &DefId) -> Option<std::cmp::Ordering> {
+ Some(Ord::cmp(self, other))
+ }
+}
+
impl DefId {
/// Makes a local `DefId` from the given `DefIndex`.
#[inline]
@@ -305,6 +323,12 @@ impl DefId {
}
}
+impl From<LocalDefId> for DefId {
+ fn from(local: LocalDefId) -> DefId {
+ local.to_def_id()
+ }
+}
+
impl<E: Encoder> Encodable<E> for DefId {
default fn encode(&self, s: &mut E) {
self.krate.encode(s);
@@ -331,7 +355,7 @@ impl fmt::Debug for DefId {
}
}
-rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId);
+rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefIdMapEntry, DefId);
/// A `LocalDefId` is equivalent to a `DefId` with `krate == LOCAL_CRATE`. Since
/// we encode this information in the type, we can ensure at compile time that
@@ -393,7 +417,12 @@ impl<D: Decoder> Decodable<D> for LocalDefId {
}
}
-rustc_data_structures::define_id_collections!(LocalDefIdMap, LocalDefIdSet, LocalDefId);
+rustc_data_structures::define_id_collections!(
+ LocalDefIdMap,
+ LocalDefIdSet,
+ LocalDefIdMapEntry,
+ LocalDefId
+);
impl<CTX: HashStableContext> HashStable<CTX> for DefId {
#[inline]