Skip to content

Commit

Permalink
Restore nightly behavior of Span::start and Span::end
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 16, 2024
1 parent 50b477d commit 44f8ff2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions build/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ pub fn byte_range(this: &Span) -> Range<usize> {
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<Span> {
this.join(other)
}
Expand Down
15 changes: 15 additions & 0 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand All @@ -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(),
}
Expand Down

0 comments on commit 44f8ff2

Please sign in to comment.