Skip to content

Commit 3978a05

Browse files
committed
Implement ord/partialord for HirId
1 parent 201b51a commit 3978a05

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

compiler/rustc_hir/src/hir_id.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::def_id::{LocalDefId, CRATE_DEF_INDEX};
2+
use std::cmp::Ordering;
23
use std::fmt;
34

45
/// Uniquely identifies a node in the HIR of the current crate. It is
@@ -18,6 +19,22 @@ pub struct HirId {
1819
pub local_id: ItemLocalId,
1920
}
2021

22+
impl Ord for HirId {
23+
fn cmp(&self, other: &Self) -> Ordering {
24+
(self.owner.local_def_index, self.local_id)
25+
.cmp(&(other.owner.local_def_index, other.local_id))
26+
}
27+
}
28+
29+
impl PartialOrd for HirId {
30+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
31+
Some(
32+
(self.owner.local_def_index, self.local_id)
33+
.cmp(&(other.owner.local_def_index, other.local_id)),
34+
)
35+
}
36+
}
37+
2138
impl HirId {
2239
pub fn expect_owner(self) -> LocalDefId {
2340
assert_eq!(self.local_id.index(), 0);

0 commit comments

Comments
 (0)