Tracking issue for proc_macro::Span inspection APIs · Issue #54725 · rust-lang/rust (original) (raw)

This issue is intended to track a number of unstable APIs which are used to inspect the contents of a Span for information like the file name, byte position, manufacturing new spans, combining them, etc.

This issue tracks the proc_macro_span unstable feature.

Public API

Already stabilized:

impl Span { // as proc_macro_source_text pub fn source_text(&self) -> Option;

// as `proc_macro_span_location`
pub fn start(&self) -> Span;
pub fn end(&self) -> Span;
pub fn line(&self) -> usize;
pub fn column(&self) -> usize;

}

impl Group { // as proc_macro_group_span pub fn span_open(&self) -> Span; pub fn span_close(&self) -> Span; }

About to be stabilized:

impl Span { // as proc_macro_span_file pub fn file(&self) -> String; // Mapped file name, for display purposes. pub fn local_file(&self) -> Option; // Real file name as it exists on disk. }

Close to stabilization, pending some bikeshedding:

impl Span { pub fn byte_range(&self) -> Range; // Open question: Do we want to use the old or new Range type? }

Things that require more discussion:

impl Span { pub fn eq(&self, other: &Span) -> bool; pub fn join(&self, other: Span) -> Option; pub fn parent(&self) -> Option; pub fn source(&self) -> Span; }

impl Literal { pub fn subspan<R: RangeBounds>(&self, range: R) -> Option; }

History: