Struct Span

struct Span(_)

A region of source code, along with macro expansion information.

Implementations

impl Span

fn def_site() -> Span

A span that resolves at the macro definition site.

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.

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.

fn parent(self: &Self) -> Option<Span>

The Span for the tokens in the previous macro expansion from which self was generated from, if any.

fn source(self: &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.

fn byte_range(self: &Self) -> Range<usize>

Returns the span's byte position range in the source file.

fn start(self: &Self) -> Span

Creates an empty span pointing to directly before this span.

fn end(self: &Self) -> Span

Creates an empty span pointing to directly after this span.

fn line(self: &Self) -> usize

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().

fn column(self: &Self) -> usize

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().

fn file(self: &Self) -> String

The path to the source file in which this span occurs, for display purposes.

This might not correspond to a valid file system path. It might be remapped (e.g. "/src/lib.rs") or an artificial path (e.g. "<command line>").

fn local_file(self: &Self) -> Option<PathBuf>

The path to the source file in which this span occurs on the local file system.

This is the actual path on disk. It is unaffected by path remapping.

This path should not be embedded in the output of the macro; prefer file() instead.

fn join(self: &Self, other: Span) -> Option<Span>

Creates a new span encompassing self and other.

Returns None if self and other are from different files.

fn resolved_at(self: &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.

fn located_at(self: &Self, other: Span) -> Span

Creates a new span with the same name resolution behavior as self but with the line/column information of other.

fn eq(self: &Self, other: &Span) -> bool

Compares two spans to see if they're equal.

fn source_text(self: &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.

fn error<T: Into<String>>(self: Self, message: T) -> Diagnostic

Creates a new Diagnostic with the given message at the span self.

fn warning<T: Into<String>>(self: Self, message: T) -> Diagnostic

Creates a new Diagnostic with the given message at the span self.

fn note<T: Into<String>>(self: Self, message: T) -> Diagnostic

Creates a new Diagnostic with the given message at the span self.

fn help<T: Into<String>>(self: Self, message: T) -> Diagnostic

Creates a new Diagnostic with the given message at the span self.

impl Clone for Span

fn clone(self: &Self) -> Span

impl Copy for Span

impl Debug for Span

fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result

impl Freeze for Span

impl MultiSpan for crate::Span

fn into_spans(self: Self) -> Vec<Span>

impl RefUnwindSafe for Span

impl Send for Span

impl Sync for Span

impl Unpin for Span

impl UnwindSafe for Span

impl<T> Any for Span

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Span

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Span

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Span

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for Span

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Span

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for Span

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Span

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Span

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>