Struct rustc_span::source_map::SourceMap
source · 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
impl SourceMap
pub fn new(path_mapping: FilePathMapping) -> SourceMap
pub fn with_inputs(_: SourceMapInputs) -> SourceMap
pub fn path_mapping(&self) -> &FilePathMapping
pub fn file_exists(&self, path: &Path) -> bool
pub fn load_file(&self, path: &Path) -> Result<Lrc<SourceFile>>
sourcepub fn load_binary_file(&self, path: &Path) -> Result<(Lrc<[u8]>, Span)>
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.
pub fn files(&self) -> MappedReadGuard<'_, MonotonicVec<Lrc<SourceFile>>>
pub fn source_file_by_stable_id( &self, stable_id: StableSourceFileId, ) -> Option<Lrc<SourceFile>>
fn register_source_file( &self, file_id: StableSourceFileId, file: SourceFile, ) -> Result<Lrc<SourceFile>, OffsetOverflowError>
sourcepub fn new_source_file(
&self,
filename: FileName,
src: String,
) -> Lrc<SourceFile>
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.
fn try_new_source_file( &self, filename: FileName, src: String, ) -> Result<Lrc<SourceFile>, OffsetOverflowError>
sourcepub fn new_imported_source_file(
&self,
filename: FileName,
src_hash: 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>
pub fn new_imported_source_file( &self, filename: FileName, src_hash: 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.
sourcepub fn doctest_offset_line(&self, file: &FileName, orig: usize) -> usize
pub fn doctest_offset_line(&self, file: &FileName, orig: usize) -> usize
If there is a doctest offset, applies it to the line.
sourcepub fn lookup_source_file(&self, pos: BytePos) -> Lrc<SourceFile>
pub fn lookup_source_file(&self, pos: BytePos) -> Lrc<SourceFile>
Return the SourceFile that contains the given BytePos
sourcepub fn lookup_char_pos(&self, pos: BytePos) -> Loc
pub fn lookup_char_pos(&self, pos: BytePos) -> Loc
Looks up source information about a BytePos
.
sourcepub fn lookup_line(
&self,
pos: BytePos,
) -> Result<SourceFileAndLine, Lrc<SourceFile>>
pub fn lookup_line( &self, pos: BytePos, ) -> Result<SourceFileAndLine, Lrc<SourceFile>>
If the corresponding SourceFile
is empty, does not return a line number.
pub fn span_to_string( &self, sp: Span, filename_display_pref: FileNameDisplayPreference, ) -> String
pub fn span_to_location_info( &self, sp: Span, ) -> (Option<Lrc<SourceFile>>, usize, usize, usize, usize)
sourcepub fn span_to_embeddable_string(&self, sp: Span) -> String
pub fn span_to_embeddable_string(&self, sp: Span) -> String
Format the span location suitable for embedding in build artifacts
sourcepub fn span_to_diagnostic_string(&self, sp: Span) -> String
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.
pub fn span_to_filename(&self, sp: Span) -> FileName
pub fn filename_for_diagnostics<'a>( &self, filename: &'a FileName, ) -> FileNameDisplay<'a>
pub fn is_multiline(&self, sp: Span) -> bool
pub fn is_valid_span(&self, sp: Span) -> Result<(Loc, Loc), SpanLinesError>
pub fn is_line_before_span_empty(&self, sp: Span) -> bool
pub fn span_to_lines(&self, sp: Span) -> FileLinesResult
sourcefn span_to_source<F, T>(
&self,
sp: Span,
extract_source: F,
) -> Result<T, SpanSnippetError>
fn span_to_source<F, T>( &self, sp: Span, extract_source: F, ) -> 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.
pub fn is_span_accessible(&self, sp: Span) -> bool
sourcepub fn span_to_snippet(&self, sp: Span) -> Result<String, SpanSnippetError>
pub fn span_to_snippet(&self, sp: Span) -> Result<String, SpanSnippetError>
Returns the source snippet as String
corresponding to the given Span
.
pub fn span_to_margin(&self, sp: Span) -> Option<usize>
pub fn indentation_before(&self, sp: Span) -> Option<String>
sourcepub fn span_to_prev_source(&self, sp: Span) -> Result<String, SpanSnippetError>
pub fn span_to_prev_source(&self, sp: Span) -> Result<String, SpanSnippetError>
Returns the source snippet as String
before the given Span
.
sourcepub fn span_extend_to_prev_char(
&self,
sp: Span,
c: char,
accept_newlines: bool,
) -> Span
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.
sourcepub fn span_extend_to_prev_str(
&self,
sp: Span,
pat: &str,
accept_newlines: bool,
include_whitespace: bool,
) -> Option<Span>
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.
sourcepub fn span_to_next_source(&self, sp: Span) -> Result<String, SpanSnippetError>
pub fn span_to_next_source(&self, sp: Span) -> Result<String, SpanSnippetError>
Returns the source snippet as String
after the given Span
.
sourcepub fn span_extend_while(
&self,
span: Span,
f: impl Fn(char) -> bool,
) -> Result<Span, SpanSnippetError>
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
sourcepub fn span_extend_while_whitespace(&self, span: Span) -> Span
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.
sourcepub fn span_extend_prev_while(
&self,
span: Span,
f: impl Fn(char) -> bool,
) -> Result<Span, SpanSnippetError>
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
sourcepub fn span_extend_to_next_char(
&self,
sp: Span,
c: char,
accept_newlines: bool,
) -> Span
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
.
sourcepub fn span_extend_to_line(&self, sp: Span) -> Span
pub fn span_extend_to_line(&self, sp: Span) -> Span
Extends the given Span
to contain the entire line it is on.
sourcepub fn span_until_char(&self, sp: Span, c: char) -> Span
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
.
sourcepub fn span_wrapped_by_angle_or_parentheses(&self, span: Span) -> bool
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 ‘()’
sourcepub fn span_through_char(&self, sp: Span, c: char) -> Span
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
.
sourcepub fn span_until_non_whitespace(&self, sp: Span) -> Span
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.
sourcepub fn span_until_whitespace(&self, sp: Span) -> Span
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.
sourcepub fn span_take_while<P>(&self, sp: Span, predicate: P) -> Span
pub fn span_take_while<P>(&self, sp: Span, predicate: P) -> Span
Given a Span
, gets a shorter one until predicate
yields false
.
sourcepub fn guess_head_span(&self, sp: Span) -> Span
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.
sourcepub fn start_point(&self, sp: Span) -> Span
pub fn start_point(&self, sp: Span) -> Span
Returns a new span representing just the first character of the given span.
sourcepub fn end_point(&self, sp: Span) -> Span
pub fn end_point(&self, sp: Span) -> Span
Returns a new span representing just the last character of this span.
sourcepub fn next_point(&self, sp: Span) -> Span
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
sourcepub fn span_look_ahead(
&self,
span: Span,
expect: &str,
limit: Option<usize>,
) -> Option<Span>
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
sourcefn find_width_of_character_at_span(&self, sp: Span, forwards: bool) -> u32
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.
pub fn get_source_file(&self, filename: &FileName) -> Option<Lrc<SourceFile>>
sourcepub fn lookup_byte_offset(&self, bpos: BytePos) -> SourceFileAndBytePos
pub fn lookup_byte_offset(&self, bpos: BytePos) -> SourceFileAndBytePos
For a global BytePos
, computes the local offset within the containing SourceFile
.
sourcepub fn lookup_source_file_idx(&self, pos: BytePos) -> usize
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
pub fn count_lines(&self) -> usize
pub fn ensure_source_file_source_present( &self, source_file: &SourceFile, ) -> bool
pub fn is_imported(&self, sp: Span) -> bool
Auto Trait Implementations§
impl !Freeze for SourceMap
impl !RefUnwindSafe for SourceMap
impl !Send for SourceMap
impl !Sync for SourceMap
impl Unpin for SourceMap
impl !UnwindSafe for SourceMap
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moresource§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
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