pub struct SourceMap {
    files: RwLock<SourceMapFiles>,
    file_loader: IntoDynSyncSend<Box<dyn FileLoader + Sync + Send>>,
    path_mapping: FilePathMapping,
    hash_kind: SourceFileHashAlgorithm,
}

Fields§

§files: RwLock<SourceMapFiles>§file_loader: IntoDynSyncSend<Box<dyn FileLoader + Sync + Send>>§path_mapping: FilePathMapping§hash_kind: SourceFileHashAlgorithm

The algorithm used for hashing the contents of each source file.

Implementations§

source§

impl SourceMap

source

pub fn new(path_mapping: FilePathMapping) -> SourceMap

source

pub fn with_file_loader_and_hash_kind( file_loader: Box<dyn FileLoader + Sync + Send>, path_mapping: FilePathMapping, hash_kind: SourceFileHashAlgorithm ) -> SourceMap

source

pub fn path_mapping(&self) -> &FilePathMapping

source

pub fn file_exists(&self, path: &Path) -> bool

source

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

source

pub fn load_binary_file(&self, path: &Path) -> Result<Lrc<[u8]>>

Loads source file as a binary blob.

Unlike load_file, guarantees that no normalization like BOM-removal takes place.

source

pub fn files(&self) -> MappedReadGuard<'_, MonotonicVec<Lrc<SourceFile>>>

source

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

source

fn register_source_file( &self, file_id: StableSourceFileId, file: SourceFile ) -> Result<Lrc<SourceFile>, OffsetOverflowError>

source

pub fn new_source_file( &self, filename: FileName, src: String ) -> Lrc<SourceFile>

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

source

fn try_new_source_file( &self, filename: FileName, src: String ) -> Result<Lrc<SourceFile>, OffsetOverflowError>

source

pub fn new_imported_source_file( &self, filename: FileName, src_hash: SourceFileHash, name_hash: Hash128, source_len: u32, cnum: CrateNum, file_local_lines: FreezeLock<SourceFileLines>, multibyte_chars: Vec<MultiByteChar>, non_narrow_chars: Vec<NonNarrowChar>, normalized_pos: Vec<NormalizedPos>, metadata_index: u32 ) -> Lrc<SourceFile>

Allocates a new SourceFile representing a source file from an external crate. The source code of such an “imported SourceFile” is not available, but we still know enough to generate accurate debuginfo location information for things inlined from other crates.

source

pub fn doctest_offset_line(&self, file: &FileName, orig: usize) -> usize

If there is a doctest offset, applies it to the line.

source

pub fn lookup_source_file(&self, pos: BytePos) -> Lrc<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, Lrc<SourceFile>>

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

source

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

source

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

source

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

Format the span location suitable for embedding in build artifacts

source

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

Format the span location suitable for pretty printing annotations with relative line numbers

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_filename(&self, sp: Span) -> FileName

source

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

source

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

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

fn span_to_source<F, T>( &self, sp: Span, extract_source: F ) -> Result<T, SpanSnippetError>where F: Fn(&str, usize, usize) -> Result<T, SpanSnippetError>,

Extracts the source surrounding the given Span using the extract_source function. The extract function takes three arguments: a string slice containing the source, an index in the slice for the beginning of the span and an index in the slice for the end of the span.

source

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

source

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

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

source

pub fn span_to_margin(&self, sp: Span) -> Option<usize>

source

pub fn indentation_before(&self, sp: Span) -> Option<String>

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 span_extend_to_prev_char( &self, sp: Span, c: char, accept_newlines: bool ) -> Span

Extends the given Span to just after the previous occurrence of c. Return the same span if no character could be found or if an error occurred while retrieving the code snippet.

source

pub fn span_extend_to_prev_str( &self, sp: Span, pat: &str, accept_newlines: bool, include_whitespace: bool ) -> Option<Span>

Extends the given Span to just after the previous occurrence of pat when surrounded by whitespace. Returns None if the pattern could not be found or if an error occurred while retrieving the code snippet.

source

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

Returns the source snippet as String after the given Span.

source

pub fn span_extend_while( &self, span: Span, f: impl Fn(char) -> bool ) -> Result<Span, SpanSnippetError>

Extends the given Span while the next character matches the predicate

source

pub fn span_extend_prev_while( &self, span: Span, f: impl Fn(char) -> bool ) -> Result<Span, SpanSnippetError>

Extends the given Span to previous character while the previous character matches the predicate

source

pub fn span_extend_to_next_char( &self, sp: Span, c: char, accept_newlines: bool ) -> Span

Extends the given Span to just before the next occurrence of c.

source

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

Extends the given Span to contain the entire line it is on.

source

pub fn span_until_char(&self, sp: Span, c: char) -> Span

Given a Span, tries to get a shorter span ending before the first occurrence of char c.

source

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

Given a ‘Span’, tries to tell if it’s wrapped by “<>” or “()” the algorithm searches if the next character is ‘>’ or ‘)’ after skipping white space then searches the previous character to match ‘<’ or ‘(’ after skipping white space return true if wrapped by ‘<>’ or ‘()’

source

pub fn span_through_char(&self, sp: Span, c: char) -> Span

Given a Span, tries to get a shorter span ending just after the first occurrence of char c.

source

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

Given a Span, gets a new Span covering the first token and all its trailing whitespace or the original Span.

If sp points to "let mut x", then a span pointing at "let " will be returned.

source

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

Given a Span, gets a new Span covering the first token without its trailing whitespace or the original Span in case of error.

If sp points to "let mut x", then a span pointing at "let" will be returned.

source

pub fn span_take_while<P>(&self, sp: Span, predicate: P) -> Spanwhere P: for<'r> FnMut(&'r char) -> bool,

Given a Span, gets a shorter one until predicate yields false.

source

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

Given a Span, return a span ending in the closest {. This is useful when you have a Span enclosing a whole item but we need to point at only the head (usually the first line) of that item.

Only suitable for diagnostics.

source

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

Returns a new span representing just the first character of the given span.

source

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

Returns a new span representing just the last character of this span.

source

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

Returns a new span representing the next character after the end-point of this span. Special cases:

  • if span is a dummy one, returns the same span
  • if next_point reached the end of source, return a span exceeding the end of source, which means sm.span_to_snippet(next_point) will get Err
  • respect multi-byte characters
source

pub fn span_look_ahead( &self, span: Span, expect: &str, limit: Option<usize> ) -> Option<Span>

Check whether span is followed by some specified expected string in limit scope

source

fn find_width_of_character_at_span(&self, sp: Span, forwards: bool) -> u32

Finds the width of the character, either before or after the end of provided span, depending on the forwards parameter.

source

pub fn get_source_file(&self, filename: &FileName) -> Option<Lrc<SourceFile>>

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, since source_files is a MonotonicVec

source

pub fn count_lines(&self) -> usize

source

pub fn ensure_source_file_source_present( &self, source_file: &SourceFile ) -> bool

source

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

source

pub fn stmt_span(&self, stmt_span: Span, block_span: Span) -> Span

Gets the span of a statement. If the statement is a macro expansion, the span in the context of the block span is found. The trailing semicolon is included on a best-effort basis.

source

pub fn mac_call_stmt_semi_span(&self, mac_call: Span) -> Option<Span>

Tries to find the span of the semicolon of a macro call statement. The input must be the call site span of a statement from macro expansion.

//       v output
   mac!();
// ^^^^^^ input

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 120 bytes