Skip to content

Commit

Permalink
Make columns 1 based
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Aug 3, 2021
1 parent b4a85da commit 50fcd45
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions library/proc_macro/src/lib.rs
Expand Up @@ -348,13 +348,13 @@ impl Span {
/// Gets the starting line/column in the source file for this span.
#[unstable(feature = "proc_macro_span", issue = "54725")]
pub fn start(&self) -> LineColumn {
self.0.start()
self.0.start().add_1_to_column()
}

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

/// Creates a new span encompassing `self` and `other`.
Expand Down Expand Up @@ -432,12 +432,18 @@ pub struct LineColumn {
/// The 1-indexed line in the source file on which the span starts or ends (inclusive).
#[unstable(feature = "proc_macro_span", issue = "54725")]
pub line: usize,
/// The 0-indexed column (in UTF-8 characters) in the source file on which
/// The 1-indexed column (in UTF-8 characters) in the source file on which
/// the span starts or ends (inclusive).
#[unstable(feature = "proc_macro_span", issue = "54725")]
pub column: usize,
}

impl LineColumn {
fn add_1_to_column(self) -> Self {
LineColumn { line: self.line, column: self.column + 1 }
}
}

#[unstable(feature = "proc_macro_span", issue = "54725")]
impl !Send for LineColumn {}
#[unstable(feature = "proc_macro_span", issue = "54725")]
Expand Down

0 comments on commit 50fcd45

Please sign in to comment.