Remove PartialOrd
and Ord
from LocalDefId
Implement `Ord`, `PartialOrd` for SpanData
This commit is contained in:
parent
e100ec5bc7
commit
8df9248591
12 changed files with 72 additions and 24 deletions
|
@ -101,7 +101,11 @@ impl DefPathTable {
|
|||
pub struct Definitions {
|
||||
table: DefPathTable,
|
||||
|
||||
// FIXME(eddyb) ideally all `LocalDefId`s would be HIR owners.
|
||||
/// Only [`LocalDefId`]s for items and item-like are HIR owners.
|
||||
/// The associated `HirId` has a `local_id` of `0`.
|
||||
/// Generic parameters and closures are also assigned a `LocalDefId` but are not HIR owners.
|
||||
/// Their `HirId`s are defined by their position while lowering the enclosing owner.
|
||||
// FIXME(cjgillot) Some `LocalDefId`s from `use` items are dropped during lowering and lack a `HirId`.
|
||||
pub(super) def_id_to_hir_id: IndexVec<LocalDefId, Option<hir::HirId>>,
|
||||
/// The reverse mapping of `def_id_to_hir_id`.
|
||||
pub(super) hir_id_to_def_id: FxHashMap<hir::HirId, LocalDefId>,
|
||||
|
|
|
@ -1203,7 +1203,7 @@ pub enum UnsafeSource {
|
|||
UserProvided,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Hash, Debug)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug)]
|
||||
pub struct BodyId {
|
||||
pub hir_id: HirId,
|
||||
}
|
||||
|
@ -1980,7 +1980,7 @@ pub struct FnSig<'hir> {
|
|||
// The bodies for items are stored "out of line", in a separate
|
||||
// hashmap in the `Crate`. Here we just record the hir-id of the item
|
||||
// so it can fetched later.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
|
||||
pub struct TraitItemId {
|
||||
pub def_id: LocalDefId,
|
||||
}
|
||||
|
@ -2043,7 +2043,7 @@ pub enum TraitItemKind<'hir> {
|
|||
// The bodies for items are stored "out of line", in a separate
|
||||
// hashmap in the `Crate`. Here we just record the hir-id of the item
|
||||
// so it can fetched later.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
|
||||
pub struct ImplItemId {
|
||||
pub def_id: LocalDefId,
|
||||
}
|
||||
|
@ -2644,7 +2644,7 @@ impl<'hir> VariantData<'hir> {
|
|||
// The bodies for items are stored "out of line", in a separate
|
||||
// hashmap in the `Crate`. Here we just record the hir-id of the item
|
||||
// so it can fetched later.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug, Hash)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, Hash)]
|
||||
pub struct ItemId {
|
||||
pub def_id: LocalDefId,
|
||||
}
|
||||
|
@ -2883,7 +2883,7 @@ pub enum AssocItemKind {
|
|||
// The bodies for items are stored "out of line", in a separate
|
||||
// hashmap in the `Crate`. Here we just record the hir-id of the item
|
||||
// so it can fetched later.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug)]
|
||||
pub struct ForeignItemId {
|
||||
pub def_id: LocalDefId,
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::fmt;
|
|||
/// the `local_id` part of the `HirId` changing, which is a very useful property in
|
||||
/// incremental compilation where we have to persist things through changes to
|
||||
/// the code base.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
#[derive(Encodable, Decodable)]
|
||||
pub struct HirId {
|
||||
pub owner: LocalDefId,
|
||||
|
@ -32,6 +32,10 @@ impl HirId {
|
|||
pub fn make_owner(owner: LocalDefId) -> Self {
|
||||
Self { owner, local_id: ItemLocalId::from_u32(0) }
|
||||
}
|
||||
|
||||
pub fn index(self) -> (usize, usize) {
|
||||
(rustc_index::vec::Idx::index(self.owner), rustc_index::vec::Idx::index(self.local_id))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for HirId {
|
||||
|
@ -40,6 +44,18 @@ impl fmt::Display for HirId {
|
|||
}
|
||||
}
|
||||
|
||||
impl Ord for HirId {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
(self.index()).cmp(&(other.index()))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for HirId {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
Some(self.cmp(&other))
|
||||
}
|
||||
}
|
||||
|
||||
rustc_data_structures::define_id_collections!(HirIdMap, HirIdSet, HirId);
|
||||
rustc_data_structures::define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue