Struct rustc_span::source_map::SourceMap
source · [−]pub struct SourceMap {
used_address_space: AtomicU32,
files: RwLock<SourceMapFiles>,
file_loader: Box<dyn FileLoader + Sync + Send>,
path_mapping: FilePathMapping,
hash_kind: SourceFileHashAlgorithm,
}
Fields
used_address_space: AtomicU32
The address space below this value is currently used by the files in the source map.
files: RwLock<SourceMapFiles>
file_loader: Box<dyn FileLoader + Sync + Send>
path_mapping: FilePathMapping
hash_kind: SourceFileHashAlgorithm
The algorithm used for hashing the contents of each source file.
Implementations
sourceimpl SourceMap
impl SourceMap
pub fn new(path_mapping: FilePathMapping) -> SourceMap
pub fn with_file_loader_and_hash_kind(
file_loader: Box<dyn FileLoader + Sync + Send>,
path_mapping: FilePathMapping,
hash_kind: SourceFileHashAlgorithm
) -> 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<Vec<u8>>
pub fn load_binary_file(&self, path: &Path) -> Result<Vec<u8>>
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 allocate_address_space(
&self,
size: usize
) -> Result<usize, 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,
name_hash: u128,
source_len: usize,
cnum: CrateNum,
file_local_lines: Lock<SourceFileLines>,
file_local_multibyte_chars: Vec<MultiByteChar>,
file_local_non_narrow_chars: Vec<NonNarrowChar>,
file_local_normalized_pos: Vec<NormalizedPos>,
original_start_pos: BytePos,
metadata_index: u32
) -> Lrc<SourceFile>
pub fn new_imported_source_file(
&self,
filename: FileName,
src_hash: SourceFileHash,
name_hash: u128,
source_len: usize,
cnum: CrateNum,
file_local_lines: Lock<SourceFileLines>,
file_local_multibyte_chars: Vec<MultiByteChar>,
file_local_non_narrow_chars: Vec<NonNarrowChar>,
file_local_normalized_pos: Vec<NormalizedPos>,
original_start_pos: BytePos,
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.
pub fn doctest_offset_line(&self, file: &FileName, orig: usize) -> usize
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
.
pub fn lookup_line(
&self,
pos: BytePos
) -> Result<SourceFileAndLine, Lrc<SourceFile>>
fn span_to_string(
&self,
sp: Span,
filename_display_pref: FileNameDisplayPreference
) -> String
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_relative_line_string(&self, sp: Span, relative_to: Span) -> String
pub fn span_to_relative_line_string(&self, sp: Span, relative_to: Span) -> String
Format the span location suitable for pretty printing anotations with relative line numbers
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>where
F: Fn(&str, usize, usize) -> Result<T, SpanSnippetError>,
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.
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_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_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) -> Spanwhere
P: for<'r> FnMut(&'r char) -> bool,
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
.
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.
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
.
pub fn lookup_source_file_idx(&self, pos: BytePos) -> usize
pub fn count_lines(&self) -> usize
pub fn ensure_source_file_source_present(
&self,
source_file: Lrc<SourceFile>
) -> bool
pub fn is_imported(&self, sp: Span) -> bool
sourcepub fn stmt_span(&self, stmt_span: Span, block_span: Span) -> Span
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.
sourcepub fn mac_call_stmt_semi_span(&self, mac_call: Span) -> Option<Span>
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
impl !RefUnwindSafe for SourceMap
impl !Send for SourceMap
impl !Sync for SourceMap
impl Unpin for SourceMap
impl !UnwindSafe for SourceMap
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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