Struct proc_macro::Span
1.29.0 · source · pub struct Span(_);
Expand description
A region of source code, along with macro expansion information.
Implementations
sourceimpl 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 start(&self) -> LineColumn
🔬This is a nightly-only experimental API. (proc_macro_span
#54725)
pub fn start(&self) -> LineColumn
proc_macro_span
#54725)Gets the starting line/column in the source file for this span.
sourcepub fn end(&self) -> LineColumn
🔬This is a nightly-only experimental API. (proc_macro_span
#54725)
pub fn end(&self) -> LineColumn
proc_macro_span
#54725)Gets the ending line/column in the source file for this span.
sourcepub fn before(&self) -> Span
🔬This is a nightly-only experimental API. (proc_macro_span_shrink
#87552)
pub fn before(&self) -> Span
proc_macro_span_shrink
#87552)Creates an empty span pointing to directly before this span.
sourcepub fn after(&self) -> Span
🔬This is a nightly-only experimental API. (proc_macro_span_shrink
#87552)
pub fn after(&self) -> Span
proc_macro_span_shrink
#87552)Creates an empty span pointing to directly after this span.
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.67.0-dev · 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
.
Trait Implementations
sourceimpl MultiSpan for Span
impl MultiSpan for Span
sourcefn into_spans(self) -> Vec<Span>
fn into_spans(self) -> Vec<Span>
proc_macro_diagnostic
#54140)self
into a Vec<Span>
.