diff options
Diffstat (limited to 'compiler/rustc_span/src/lib.rs')
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 50 |
1 files changed, 10 insertions, 40 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 99ac973497e..266956d63d7 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -467,46 +467,23 @@ 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)] +#[derive(Clone, Copy, Hash, PartialEq, Eq, derivative::Derivative)] +#[derivative(PartialOrd, Ord)] pub struct SpanData { pub lo: BytePos, pub hi: BytePos, /// Information about where the macro came from, if this piece of /// code was created by a macro expansion. + #[derivative(PartialOrd = "ignore", Ord = "ignore")] + // `SyntaxContext` does not implement `Ord`. + // The other fields are enough to determine in-file order. pub ctxt: SyntaxContext, + #[derivative(PartialOrd = "ignore", Ord = "ignore")] + // `LocalDefId` does not implement `Ord`. + // The other fields are enough to determine in-file order. 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 { @@ -525,8 +502,9 @@ impl SpanData { fn with_ctxt(&self, ctxt: SyntaxContext) -> Span { Span::new(self.lo, self.hi, ctxt, self.parent) } + /// Avoid if possible, `Span::with_parent` should be preferred. #[inline] - pub fn with_parent(&self, parent: Option<LocalDefId>) -> Span { + fn with_parent(&self, parent: Option<LocalDefId>) -> Span { Span::new(self.lo, self.hi, self.ctxt, parent) } /// Returns `true` if this is a dummy span with any hygienic context. @@ -580,14 +558,6 @@ impl Span { pub fn with_ctxt(self, ctxt: SyntaxContext) -> Span { self.map_ctxt(|_| ctxt) } - #[inline] - pub fn parent(self) -> Option<LocalDefId> { - self.data().parent - } - #[inline] - pub fn with_parent(self, ctxt: Option<LocalDefId>) -> Span { - self.data().with_parent(ctxt) - } #[inline] pub fn is_visible(self, sm: &SourceMap) -> bool { |
