Struct rustc_span::source_map::SourceMap [−][src]
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: AtomicU32The 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: FilePathMappinghash_kind: SourceFileHashAlgorithmThe algorithm used for hashing the contents of each source file.
Implementations
pub fn with_file_loader_and_hash_kind(
file_loader: Box<dyn FileLoader + Sync + Send>,
path_mapping: FilePathMapping,
hash_kind: SourceFileHashAlgorithm
) -> SourceMap
Loads source file as a binary blob.
Unlike load_file, guarantees that no normalization like BOM-removal
takes place.
pub fn source_file_by_stable_id(
&self,
stable_id: StableSourceFileId
) -> Option<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>
pub fn new_imported_source_file(
&self,
filename: FileName,
src_hash: SourceFileHash,
name_hash: u128,
source_len: usize,
cnum: CrateNum,
file_local_lines: Vec<BytePos>,
file_local_multibyte_chars: Vec<MultiByteChar>,
file_local_non_narrow_chars: Vec<NonNarrowChar>,
file_local_normalized_pos: Vec<NormalizedPos>,
original_start_pos: BytePos,
original_end_pos: BytePos
) -> 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: Vec<BytePos>,
file_local_multibyte_chars: Vec<MultiByteChar>,
file_local_non_narrow_chars: Vec<NonNarrowChar>,
file_local_normalized_pos: Vec<NormalizedPos>,
original_start_pos: BytePos,
original_end_pos: BytePos
) -> 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.
Return the SourceFile that contains the given BytePos
Looks up source information about a BytePos.
fn span_to_string(
&self,
sp: Span,
filename_display_pref: FileNameDisplayPreference
) -> String
Format the span location suitable for embedding in build artifacts
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.
fn 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.
Returns whether or not this span points into a file
in the current crate. This may be false for spans
produced by a macro expansion, or for spans associated
with the definition of an item in a foreign crate
Returns the source snippet as String corresponding to the given Span.
Returns the source snippet as String before the given 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.
Extends the given Span to just after the previous occurrence of pat when surrounded by
whitespace. Returns the same span if no character could be found or if an error occurred
while retrieving the code snippet.
Returns the source snippet as String after the given Span.
pub 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
Extends the given Span to just after the next occurrence of c.
Given a Span, tries to get a shorter span ending before the first occurrence of char
c.
Given a Span, tries to get a shorter span ending just after the first occurrence of char
c.
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.
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.
Given a Span, gets a shorter one until predicate yields false.
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.
Returns a new span representing just the first character of the given span.
Returns a new span representing just the last character of this span.
Returns a new span representing the next character after the end-point of this span.
Finds the width of the character, either before or after the end of provided span,
depending on the forwards parameter.
For a global BytePos, computes the local offset within the containing SourceFile.
Takes the span of a type parameter in a function signature and try to generate a span for the function name (with generics) and a new snippet for this span with the pointed type parameter as a new local type parameter.
For instance:
// Given span
fn my_function(param: T)
// ^ Original span
// Result
fn my_function(param: T)
// ^^^^^^^^^^^ Generated span with snippet `my_function<T>`Attention: The method used is very fragile since it essentially duplicates the work of the
parser. If you need to use this function or something similar, please consider updating the
SourceMap functions and this function to something more robust.
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.
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!();
^^^^^^ inputAuto Trait Implementations
impl !RefUnwindSafe for SourceMap
impl !UnwindSafe for SourceMap
Blanket Implementations
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