Struct SourceMap

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

Implementations§

Source§

impl SourceMap

Source

pub fn new(hash_kind: SourceFileHashAlgorithm) -> Self

Creates a new empty source map with the given hash algorithm.

Source

pub fn empty() -> Self

Creates a new empty source map.

Source

pub fn load_file(&self, path: &Path) -> Result<Arc<SourceFile>>

Loads a file from the given path.

Source

pub fn load_stdin(&self) -> Result<Arc<SourceFile>>

Loads stdin.

Source

pub fn new_dummy_source_file( &self, path: PathBuf, src: String, ) -> Result<Arc<SourceFile>>

Loads a file with the given source string.

This is useful for testing.

Source

pub fn new_source_file( &self, filename: FileName, get_src: impl FnOnce() -> Result<String>, ) -> Result<Arc<SourceFile>>

Creates a new SourceFile.

If a file already exists in the SourceMap with the same ID, that file is returned unmodified.

Returns an error if the file is larger than 4GiB or other errors occur while creating the SourceFile.

Source

pub fn files(&self) -> ReadGuard<'_, Vec<Arc<SourceFile>>>

Source

pub fn source_file_by_file_name( &self, filename: &FileName, ) -> Option<Arc<SourceFile>>

Source

pub fn source_file_by_stable_id( &self, stable_id: StableSourceFileId, ) -> Option<Arc<SourceFile>>

Source

pub fn filename_for_diagnostics<'a>( &self, filename: &'a FileName, ) -> FileNameDisplay<'a>

Source

pub fn is_multiline(&self, span: Span) -> bool

Returns true if the given span is multi-line.

Source

pub fn span_to_snippet(&self, span: Span) -> Result<String, SpanSnippetError>

Returns the source snippet as String corresponding to the given Span.

Source

pub fn lookup_byte_offset(&self, bpos: BytePos) -> SourceFileAndBytePos

For a global BytePos, computes the local offset within the containing SourceFile.

Source

pub fn lookup_source_file_idx(&self, pos: BytePos) -> usize

Returns the index of the SourceFile (in self.files) that contains pos.

This index is guaranteed to be valid for the lifetime of this SourceMap.

Source

pub fn lookup_source_file(&self, pos: BytePos) -> Arc<SourceFile>

Return the SourceFile that contains the given BytePos.

Source

pub fn lookup_char_pos(&self, pos: BytePos) -> Loc

Looks up source information about a BytePos.

Source

pub fn lookup_line( &self, pos: BytePos, ) -> Result<SourceFileAndLine, Arc<SourceFile>>

If the corresponding SourceFile is empty, does not return a line number.

Source

pub fn span_to_prev_source(&self, sp: Span) -> Result<String, SpanSnippetError>

Returns the source snippet as String before the given Span.

Source

pub fn is_valid_span(&self, sp: Span) -> Result<(Loc, Loc), SpanLinesError>

Source

pub fn is_line_before_span_empty(&self, sp: Span) -> bool

Source

pub fn span_to_lines(&self, sp: Span) -> FileLinesResult

Source

pub fn span_to_diagnostic_string(&self, sp: Span) -> String

Format the span location to be printed in diagnostics. Must not be emitted to build artifacts as this may leak local file paths. Use span_to_embeddable_string for string suitable for embedding.

Source

pub fn span_to_string(&self, sp: Span) -> String

Source

pub fn span_to_location_info( &self, sp: Span, ) -> (Option<Arc<SourceFile>>, usize, usize, usize, usize)

Trait Implementations§

Source§

impl Default for SourceMap

Source§

fn default() -> Self

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

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, R> CollectAndApply<T, R> for T

Source§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

Source§

type Output = R

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more