Struct proc_macro::Span
1.29.0 · source · pub struct Span(/* private fields */);
Expand description
A region of source code, along with macro expansion information.
Implementations§
source§impl Span
impl Span
sourcepub fn def_site() -> Span
🔬This is a nightly-only experimental API. (proc_macro_def_site
#54724)
pub fn def_site() -> Span
proc_macro_def_site
#54724)A span that resolves at the macro definition site.
sourcepub fn call_site() -> Span
pub fn call_site() -> Span
The span of the invocation of the current procedural macro. Identifiers created with this span will be resolved as if they were written directly at the macro call location (call-site hygiene) and other code at the macro call site will be able to refer to them as well.
1.45.0 · sourcepub fn mixed_site() -> Span
pub fn mixed_site() -> Span
A span that represents macro_rules
hygiene, and sometimes resolves at the macro
definition site (local variables, labels, $crate
) and sometimes at the macro
call site (everything else).
The span location is taken from the call-site.
sourcepub fn source_file(&self) -> SourceFile
🔬This is a nightly-only experimental API. (proc_macro_span
#54725)
pub fn source_file(&self) -> SourceFile
proc_macro_span
#54725)The original source file into which this span points.
sourcepub fn parent(&self) -> Option<Span>
🔬This is a nightly-only experimental API. (proc_macro_span
#54725)
pub fn parent(&self) -> Option<Span>
proc_macro_span
#54725)The Span
for the tokens in the previous macro expansion from which
self
was generated from, if any.
sourcepub fn source(&self) -> Span
🔬This is a nightly-only experimental API. (proc_macro_span
#54725)
pub fn source(&self) -> Span
proc_macro_span
#54725)The span for the origin source code that self
was generated from. If
this Span
wasn’t generated from other macro expansions then the return
value is the same as *self
.
sourcepub fn byte_range(&self) -> Range<usize>
🔬This is a nightly-only experimental API. (proc_macro_span
#54725)
pub fn byte_range(&self) -> Range<usize>
proc_macro_span
#54725)Returns the span’s byte position range in the source file.
sourcepub fn start(&self) -> Span
🔬This is a nightly-only experimental API. (proc_macro_span
#54725)
pub fn start(&self) -> Span
proc_macro_span
#54725)Creates an empty span pointing to directly before this span.
sourcepub fn end(&self) -> Span
🔬This is a nightly-only experimental API. (proc_macro_span
#54725)
pub fn end(&self) -> Span
proc_macro_span
#54725)Creates an empty span pointing to directly after this span.
sourcepub fn line(&self) -> usize
🔬This is a nightly-only experimental API. (proc_macro_span
#54725)
pub fn line(&self) -> usize
proc_macro_span
#54725)The one-indexed line of the source file where the span starts.
To obtain the line of the span’s end, use span.end().line()
.
sourcepub fn column(&self) -> usize
🔬This is a nightly-only experimental API. (proc_macro_span
#54725)
pub fn column(&self) -> usize
proc_macro_span
#54725)The one-indexed column of the source file where the span starts.
To obtain the column of the span’s end, use span.end().column()
.
sourcepub fn join(&self, other: Span) -> Option<Span>
🔬This is a nightly-only experimental API. (proc_macro_span
#54725)
pub fn join(&self, other: Span) -> Option<Span>
proc_macro_span
#54725)Creates a new span encompassing self
and other
.
Returns None
if self
and other
are from different files.
1.45.0 · sourcepub fn resolved_at(&self, other: Span) -> Span
pub fn resolved_at(&self, other: Span) -> Span
Creates a new span with the same line/column information as self
but
that resolves symbols as though it were at other
.
1.45.0 · sourcepub fn located_at(&self, other: Span) -> Span
pub fn located_at(&self, other: Span) -> Span
Creates a new span with the same name resolution behavior as self
but
with the line/column information of other
.
sourcepub fn eq(&self, other: &Span) -> bool
🔬This is a nightly-only experimental API. (proc_macro_span
#54725)
pub fn eq(&self, other: &Span) -> bool
proc_macro_span
#54725)Compares two spans to see if they’re equal.
1.66.0 · sourcepub fn source_text(&self) -> Option<String>
pub fn source_text(&self) -> Option<String>
Returns the source text behind a span. This preserves the original source code, including spaces and comments. It only returns a result if the span corresponds to real source code.
Note: The observable result of a macro should only rely on the tokens and not on this source text. The result of this function is a best effort to be used for diagnostics only.
sourcepub fn error<T: Into<String>>(self, message: T) -> Diagnostic
🔬This is a nightly-only experimental API. (proc_macro_diagnostic
#54140)
pub fn error<T: Into<String>>(self, message: T) -> Diagnostic
proc_macro_diagnostic
#54140)Creates a new Diagnostic
with the given message
at the span
self
.
sourcepub fn warning<T: Into<String>>(self, message: T) -> Diagnostic
🔬This is a nightly-only experimental API. (proc_macro_diagnostic
#54140)
pub fn warning<T: Into<String>>(self, message: T) -> Diagnostic
proc_macro_diagnostic
#54140)Creates a new Diagnostic
with the given message
at the span
self
.