Struct proc_macro::Span
1.29.0 · source · [−]pub struct Span(_);Expand description
A region of source code, along with macro expansion information.
Implementations
impl Span
source
impl Span
sourcepub fn call_site() -> Span
source
pub fn call_site() -> Span
sourceThe 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.
pub fn mixed_site() -> Span
1.45.0 · source
pub fn mixed_site() -> Span
1.45.0 · sourceA 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.
pub fn source_file(&self) -> SourceFile
source
pub fn source_file(&self) -> SourceFile
sourceThe original source file into which this span points.
pub fn parent(&self) -> Option<Span>
source
pub fn parent(&self) -> Option<Span>
sourceThe Span for the tokens in the previous macro expansion from which
self was generated from, if any.
pub fn source(&self) -> Span
source
pub fn source(&self) -> Span
sourceThe 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.
pub fn start(&self) -> LineColumn
source
pub fn start(&self) -> LineColumn
sourceGets the starting line/column in the source file for this span.
pub fn end(&self) -> LineColumn
source
pub fn end(&self) -> LineColumn
sourceGets the ending line/column in the source file for this span.
pub fn join(&self, other: Span) -> Option<Span>
source
pub fn join(&self, other: Span) -> Option<Span>
sourceCreates a new span encompassing self and other.
Returns None if self and other are from different files.
pub fn resolved_at(&self, other: Span) -> Span
1.45.0 · source
pub fn resolved_at(&self, other: Span) -> Span
1.45.0 · sourceCreates a new span with the same line/column information as self but
that resolves symbols as though it were at other.
pub fn located_at(&self, other: Span) -> Span
1.45.0 · source
pub fn located_at(&self, other: Span) -> Span
1.45.0 · sourceCreates a new span with the same name resolution behavior as self but
with the line/column information of other.
pub fn source_text(&self) -> Option<String>
source
pub fn source_text(&self) -> Option<String>
sourceReturns 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.
pub fn error<T: Into<String>>(self, message: T) -> Diagnostic
source
pub fn error<T: Into<String>>(self, message: T) -> Diagnostic
sourceCreates a new Diagnostic with the given message at the span
self.
pub fn warning<T: Into<String>>(self, message: T) -> Diagnostic
source
pub fn warning<T: Into<String>>(self, message: T) -> Diagnostic
sourceCreates a new Diagnostic with the given message at the span
self.
pub fn note<T: Into<String>>(self, message: T) -> Diagnostic
source
pub fn note<T: Into<String>>(self, message: T) -> Diagnostic
sourceCreates a new Diagnostic with the given message at the span
self.
Trait Implementations
impl Copy for Span
sourceimpl !Send for Span
sourceimpl !Sync for Span
sourceAuto Trait Implementations
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
source
impl<T> BorrowMut<T> for T where
T: ?Sized,
sourcefn borrow_mut(&mut self) -> &mut T
const: unstable · source
fn borrow_mut(&mut self) -> &mut T
const: unstable · sourceMutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
source
impl<T> ToOwned for T where
T: Clone,
sourcetype Owned = T
type Owned = T
The resulting type after obtaining ownership.
fn clone_into(&self, target: &mut T)
source
fn clone_into(&self, target: &mut T)
sourceUses borrowed data to replace owned data, usually by cloning. Read more