Skip to content

Commit 85b5f12

Browse files
committed
Auto merge of rust-lang#87712 - est31:line-column-1-based, r=petrochenkov
Proc macro spans: make columns 1 based This makes proc macro spans consistent with the `column!()` macro as well as `std::panic::Location`, as both are 1-based. rust-lang#54725 (comment)
2 parents adeddc3 + e5baf5d commit 85b5f12

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

proc_macro/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,13 @@ impl Span {
348348
/// Gets the starting line/column in the source file for this span.
349349
#[unstable(feature = "proc_macro_span", issue = "54725")]
350350
pub fn start(&self) -> LineColumn {
351-
self.0.start()
351+
self.0.start().add_1_to_column()
352352
}
353353

354354
/// Gets the ending line/column in the source file for this span.
355355
#[unstable(feature = "proc_macro_span", issue = "54725")]
356356
pub fn end(&self) -> LineColumn {
357-
self.0.end()
357+
self.0.end().add_1_to_column()
358358
}
359359

360360
/// Creates a new span encompassing `self` and `other`.
@@ -432,12 +432,18 @@ pub struct LineColumn {
432432
/// The 1-indexed line in the source file on which the span starts or ends (inclusive).
433433
#[unstable(feature = "proc_macro_span", issue = "54725")]
434434
pub line: usize,
435-
/// The 0-indexed column (in UTF-8 characters) in the source file on which
436-
/// the span starts or ends (inclusive).
435+
/// The 1-indexed column (number of bytes in UTF-8 encoding) in the source
436+
/// file on which the span starts or ends (inclusive).
437437
#[unstable(feature = "proc_macro_span", issue = "54725")]
438438
pub column: usize,
439439
}
440440

441+
impl LineColumn {
442+
fn add_1_to_column(self) -> Self {
443+
LineColumn { line: self.line, column: self.column + 1 }
444+
}
445+
}
446+
441447
#[unstable(feature = "proc_macro_span", issue = "54725")]
442448
impl !Send for LineColumn {}
443449
#[unstable(feature = "proc_macro_span", issue = "54725")]

0 commit comments

Comments
 (0)