rustc_span::source_map

Struct SourceMap

Source
pub struct SourceMap {
    files: RwLock<SourceMapFiles>,
    file_loader: IntoDynSyncSend<Box<dyn FileLoader + Sync + Send>>,
    path_mapping: FilePathMapping,
    hash_kind: SourceFileHashAlgorithm,
    checksum_hash_kind: Option<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.

§checksum_hash_kind: Option<SourceFileHashAlgorithm>

Similar to hash_kind, however this algorithm is used for checksums to determine if a crate is fresh. cargo is the primary user of these.

If this is equal to hash_kind then the checksum won’t be computed twice.

Implementations§

Source§

impl SourceMap

Source

pub fn new(path_mapping: FilePathMapping) -> SourceMap

Source

pub fn with_inputs(_: SourceMapInputs) -> 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]>, Span)>

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, checksum_hash: Option<SourceFileHash>, stable_id: StableSourceFileId, source_len: u32, cnum: CrateNum, file_local_lines: FreezeLock<SourceFileLines>, multibyte_chars: Vec<MultiByteChar>, 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_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

pub 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_while_whitespace(&self, span: Span) -> Span

Extends the span to include any trailing whitespace, or returns the original span if a SpanSnippetError was encountered.

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) -> Span
where 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> Aligned for T

Source§

const ALIGN: Alignment

Alignment of Self.
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> 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> Same for T

Source§

type Output = T

Should always be Self
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
Source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

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