Skip to content

Commit 096c495

Browse files
authored
Rollup merge of #139865 - m-ou-se:stabilize-proc-macro-span-location, r=tgross35
Stabilize proc_macro::Span::{start,end,line,column}. This stabilizes part of #54725 Specifically, the part related to getting the location of a span: ```rust impl Span { pub fn start(&self) -> Span; // Empty span at the start of this span pub fn end(&self) -> Span; // Empty span at the end of this span pub fn line(&self) -> usize; // Line where the span starts pub fn column(&self) -> usize; // Column where the span starts } ``` History of this part of the API: Originally, `start` and `end` returned a `LineColumn` struct (containing the line and column). This has been simplified/changed: - No more `LineColumn`: `Span` now directly has `.line()` and `.column()` methods. This means we can easily add `.byte_offset()` or `.byte_range()` in the future if we want to. - `Span::start()` and `Span::end()` are now the equivalent of rustc's internal `shrink_to_lo()` and `shrink_to_hi()`. This means you can do e.g. `span.end().column()`, removing the need for a `span.end_column()` or similar.
2 parents 555e1d0 + c5c9362 commit 096c495

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

library/proc_macro/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -513,29 +513,29 @@ impl Span {
513513
}
514514

515515
/// Creates an empty span pointing to directly before this span.
516-
#[unstable(feature = "proc_macro_span", issue = "54725")]
516+
#[stable(feature = "proc_macro_span_location", since = "CURRENT_RUSTC_VERSION")]
517517
pub fn start(&self) -> Span {
518518
Span(self.0.start())
519519
}
520520

521521
/// Creates an empty span pointing to directly after this span.
522-
#[unstable(feature = "proc_macro_span", issue = "54725")]
522+
#[stable(feature = "proc_macro_span_location", since = "CURRENT_RUSTC_VERSION")]
523523
pub fn end(&self) -> Span {
524524
Span(self.0.end())
525525
}
526526

527527
/// The one-indexed line of the source file where the span starts.
528528
///
529529
/// To obtain the line of the span's end, use `span.end().line()`.
530-
#[unstable(feature = "proc_macro_span", issue = "54725")]
530+
#[stable(feature = "proc_macro_span_location", since = "CURRENT_RUSTC_VERSION")]
531531
pub fn line(&self) -> usize {
532532
self.0.line()
533533
}
534534

535535
/// The one-indexed column of the source file where the span starts.
536536
///
537537
/// To obtain the column of the span's end, use `span.end().column()`.
538-
#[unstable(feature = "proc_macro_span", issue = "54725")]
538+
#[stable(feature = "proc_macro_span_location", since = "CURRENT_RUSTC_VERSION")]
539539
pub fn column(&self) -> usize {
540540
self.0.column()
541541
}

0 commit comments

Comments
 (0)