Skip to content

Commit 8b76a5b

Browse files
committed
Add Span::{line, column}
1 parent 42e1e7b commit 8b76a5b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

proc_macro/src/bridge/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ macro_rules! with_api {
9797
fn byte_range($self: $S::Span) -> Range<usize>;
9898
fn start($self: $S::Span) -> $S::Span;
9999
fn end($self: $S::Span) -> $S::Span;
100+
fn line($self: $S::Span) -> usize;
101+
fn column($self: $S::Span) -> usize;
100102
fn join($self: $S::Span, other: $S::Span) -> Option<$S::Span>;
101103
fn subspan($self: $S::Span, start: Bound<usize>, end: Bound<usize>) -> Option<$S::Span>;
102104
fn resolved_at($self: $S::Span, at: $S::Span) -> $S::Span;

proc_macro/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,22 @@ impl Span {
505505
Span(self.0.end())
506506
}
507507

508+
/// The one-indexed line of the source file where the span starts.
509+
///
510+
/// To obtain the line of the span's end, use `span.end().line()`.
511+
#[unstable(feature = "proc_macro_span", issue = "54725")]
512+
pub fn line(&self) -> usize {
513+
self.0.line()
514+
}
515+
516+
/// The one-indexed column of the source file where the span starts.
517+
///
518+
/// To obtain the column of the span's end, use `span.end().column()`.
519+
#[unstable(feature = "proc_macro_span", issue = "54725")]
520+
pub fn column(&self) -> usize {
521+
self.0.column()
522+
}
523+
508524
/// Creates a new span encompassing `self` and `other`.
509525
///
510526
/// Returns `None` if `self` and `other` are from different files.

0 commit comments

Comments
 (0)