Skip to main content

SourceMap

Struct SourceMap 

Source
pub struct SourceMap { /* private fields */ }
Expand description

Generated by the preprocessor: a map from a line number in the preprocessed, unified source (Span) back to the original input file and line it came from. This lets a consumer work backwards from a parsed element’s Span to the file and line the author actually wrote.

The map is stored as a sparse, sorted list of segments. Each segment anchors one preprocessed line to an origin (file, line); the lines that follow it map by simple offset until the next segment. A segment also records the Fidelity of the preprocessed line relative to its origin – whether the preprocessor rewrote the line content (so a column can no longer be mapped back faithfully) or left it verbatim. All line numbers are 1-based.

Origin file names are interned: a file included many times, or re-anchored many times, stores its path only once.

Implementations§

Source§

impl SourceMap

Source

pub fn original_file_and_line(&self, key: usize) -> Option<SourceLine>

Given a 1-based line number in the preprocessed source file, translate that to a file name and line number as original inputs to the parsing process.

This is line-granular only; use origin_at or origin_of to also recover a column (on verbatim lines) and the Fidelity of the mapping.

Source

pub fn origin_at(&self, line: usize, col: usize) -> Origin<'_>

Translate a 1-based (line, column) position in the preprocessed source back to its Origin in the original input files.

col counts Unicode scalar values, as Span::col does. It is carried through to Origin::col only when the line is Fidelity::Verbatim; otherwise Origin::col is None. See Origin for the column-unit contract.

Source

pub fn origin_of(&self, span: Span<'_>) -> Origin<'_>

Translate the start of span back to its Origin in the original input files. Convenience for origin_at(span.line(), span.col()).

Trait Implementations§

Source§

impl Clone for SourceMap

Source§

fn clone(&self) -> SourceMap

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SourceMap

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for SourceMap

Source§

fn default() -> SourceMap

Returns the “default value” for a type. Read more
Source§

impl Eq for SourceMap

Source§

impl PartialEq for SourceMap

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SourceMap

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.