From 44f8ff2be178d16a4e3d587041ef77445274e5a1 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 16 Oct 2024 07:19:15 -0700 Subject: [PATCH] Restore nightly behavior of Span::start and Span::end --- build/probe.rs | 16 ++++++++++++++++ src/wrapper.rs | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/build/probe.rs b/build/probe.rs index 2c4947a..79c8ae2 100644 --- a/build/probe.rs +++ b/build/probe.rs @@ -13,6 +13,22 @@ pub fn byte_range(this: &Span) -> Range { this.byte_range() } +pub fn start(this: &Span) -> Span { + this.start() +} + +pub fn end(this: &Span) -> Span { + this.end() +} + +pub fn line(this: &Span) -> usize { + this.line() +} + +pub fn column(this: &Span) -> usize { + this.column() +} + pub fn join(this: &Span, other: Span) -> Option { this.join(other) } diff --git a/src/wrapper.rs b/src/wrapper.rs index 87e348d..29481c1 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -477,6 +477,12 @@ impl Span { #[cfg(span_locations)] pub fn start(&self) -> LineColumn { match self { + #[cfg(proc_macro_span)] + Span::Compiler(s) => LineColumn { + line: s.line(), + column: s.column().saturating_sub(1), + }, + #[cfg(not(proc_macro_span))] Span::Compiler(_) => LineColumn { line: 0, column: 0 }, Span::Fallback(s) => s.start(), } @@ -485,6 +491,15 @@ impl Span { #[cfg(span_locations)] pub fn end(&self) -> LineColumn { match self { + #[cfg(proc_macro_span)] + Span::Compiler(s) => { + let end = s.end(); + LineColumn { + line: end.line(), + column: end.column().saturating_sub(1), + } + } + #[cfg(not(proc_macro_span))] Span::Compiler(_) => LineColumn { line: 0, column: 0 }, Span::Fallback(s) => s.end(), }