diff options
| author | pierwill <pierwill@users.noreply.github.com> | 2021-10-30 10:11:50 -0500 |
|---|---|---|
| committer | pierwill <pierwill@users.noreply.github.com> | 2021-12-22 10:50:57 -0600 |
| commit | 8df92485919ac660273ec8dfef61d7ebb0b67a86 (patch) | |
| tree | 16e5160a3d450ffa9d16eff61383ebc96f7d2dbb /compiler/rustc_span/src | |
| parent | e100ec5bc7cd768ec17d75448b29c9ab4a39272b (diff) | |
| download | rust-8df92485919ac660273ec8dfef61d7ebb0b67a86.tar.gz rust-8df92485919ac660273ec8dfef61d7ebb0b67a86.zip | |
Remove `PartialOrd` and `Ord` from `LocalDefId`
Implement `Ord`, `PartialOrd` for SpanData
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/def_id.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 32 |
2 files changed, 32 insertions, 2 deletions
diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 64c2ef30b4d..d15befbf287 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -322,7 +322,7 @@ rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId); /// few cases where we know that only DefIds from the local crate are expected /// and a DefId from a different crate would signify a bug somewhere. This /// is when LocalDefId comes in handy. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Hash)] pub struct LocalDefId { pub local_def_index: DefIndex, } diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 2934368dfeb..3bbf2a0e456 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -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 { |
