Skip to content

Commit faee27e

Browse files
authored
Merge pull request #472 from dtolnay/startend
Restore nightly behavior of Span::start and Span::end
2 parents 50b477d + 44f8ff2 commit faee27e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

build/probe.rs

+16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ pub fn byte_range(this: &Span) -> Range<usize> {
1313
this.byte_range()
1414
}
1515

16+
pub fn start(this: &Span) -> Span {
17+
this.start()
18+
}
19+
20+
pub fn end(this: &Span) -> Span {
21+
this.end()
22+
}
23+
24+
pub fn line(this: &Span) -> usize {
25+
this.line()
26+
}
27+
28+
pub fn column(this: &Span) -> usize {
29+
this.column()
30+
}
31+
1632
pub fn join(this: &Span, other: Span) -> Option<Span> {
1733
this.join(other)
1834
}

src/wrapper.rs

+15
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ impl Span {
477477
#[cfg(span_locations)]
478478
pub fn start(&self) -> LineColumn {
479479
match self {
480+
#[cfg(proc_macro_span)]
481+
Span::Compiler(s) => LineColumn {
482+
line: s.line(),
483+
column: s.column().saturating_sub(1),
484+
},
485+
#[cfg(not(proc_macro_span))]
480486
Span::Compiler(_) => LineColumn { line: 0, column: 0 },
481487
Span::Fallback(s) => s.start(),
482488
}
@@ -485,6 +491,15 @@ impl Span {
485491
#[cfg(span_locations)]
486492
pub fn end(&self) -> LineColumn {
487493
match self {
494+
#[cfg(proc_macro_span)]
495+
Span::Compiler(s) => {
496+
let end = s.end();
497+
LineColumn {
498+
line: end.line(),
499+
column: end.column().saturating_sub(1),
500+
}
501+
}
502+
#[cfg(not(proc_macro_span))]
488503
Span::Compiler(_) => LineColumn { line: 0, column: 0 },
489504
Span::Fallback(s) => s.end(),
490505
}

0 commit comments

Comments
 (0)