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 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
pub fn source_file(&self) -> SourceFile
The original source file into which this span points.
sourcepub fn parent(&self) -> Option<Span>
pub fn parent(&self) -> Option<Span>
The Span
for the tokens in the previous macro expansion from which
self
was generated from, if any.
sourcepub fn source(&self) -> Span
pub fn source(&self) -> Span
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
pub fn start(&self) -> LineColumn
Gets the starting line/column in the source file for this span.
sourcepub fn end(&self) -> LineColumn
pub fn end(&self) -> LineColumn
Gets the ending line/column in the source file for this span.
sourcepub fn join(&self, other: Span) -> Option<Span>
pub fn join(&self, other: Span) -> Option<Span>
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 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
pub fn error<T: Into<String>>(self, message: T) -> Diagnostic
Creates a new Diagnostic
with the given message
at the span
self
.
sourcepub fn warning<T: Into<String>>(self, message: T) -> Diagnostic
pub fn warning<T: Into<String>>(self, message: T) -> Diagnostic
Creates a new Diagnostic
with the given message
at the span
self
.
sourcepub fn note<T: Into<String>>(self, message: T) -> Diagnostic
pub fn note<T: Into<String>>(self, message: T) -> Diagnostic
Creates a new Diagnostic
with the given message
at the span
self
.
Trait Implementations
impl Copy for Span
impl !Send for Span
impl !Sync for Span
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more