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
|
@ -424,7 +424,7 @@ impl FileName {
|
|||
/// `SpanData` is public because `Span` uses a thread-local interner and can't be
|
||||
/// sent to other threads, but some pieces of performance infra run in a separate thread.
|
||||
/// Using `Span` is generally preferred.
|
||||
#[derive(Clone, Copy, Hash, PartialEq, Eq, Ord, PartialOrd)]
|
||||
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
|
||||
pub struct SpanData {
|
||||
pub lo: BytePos,
|
||||
pub hi: BytePos,
|
||||
|
@ -434,6 +434,36 @@ pub struct SpanData {
|
|||
pub parent: Option<LocalDefId>,
|
||||
}
|
||||
|
||||
// Order spans by position in the file.
|
||||
impl Ord for SpanData {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
let SpanData {
|
||||
lo: s_lo,
|
||||
hi: s_hi,
|
||||
ctxt: s_ctxt,
|
||||
// `LocalDefId` does not implement `Ord`.
|
||||
// The other fields are enough to determine in-file order.
|
||||
parent: _,
|
||||
} = self;
|
||||
let SpanData {
|
||||
lo: o_lo,
|
||||
hi: o_hi,
|
||||
ctxt: o_ctxt,
|
||||
// `LocalDefId` does not implement `Ord`.
|
||||
// The other fields are enough to determine in-file order.
|
||||
parent: _,
|
||||
} = other;
|
||||
|
||||
(s_lo, s_hi, s_ctxt).cmp(&(o_lo, o_hi, o_ctxt))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for SpanData {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl SpanData {
|
||||
#[inline]
|
||||
pub fn span(&self) -> Span {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue