rustc_span - Rust (original) (raw)

Expand description

Source positions and related helper functions.

Important concepts in this module include:

Unlike most compilers, the span contains not only the position in the source code, but also various other metadata, such as the edition and macro hygiene. This metadata is stored inSyntaxContext and ExpnData.

§Note

This API is completely unstable and subject to change.

pub use hygiene::[DesugaringKind](hygiene/enum.DesugaringKind.html "enum rustc_span:🪥:DesugaringKind");

pub use hygiene::[ExpnData](hygiene/struct.ExpnData.html "struct rustc_span:🪥:ExpnData");

pub use hygiene::[ExpnHash](hygiene/struct.ExpnHash.html "struct rustc_span:🪥:ExpnHash");

pub use hygiene::[ExpnId](hygiene/struct.ExpnId.html "struct rustc_span:🪥:ExpnId");

pub use hygiene::[ExpnKind](hygiene/enum.ExpnKind.html "enum rustc_span:🪥:ExpnKind");

pub use hygiene::[LocalExpnId](hygiene/struct.LocalExpnId.html "struct rustc_span:🪥:LocalExpnId");

pub use hygiene::[MacroKind](hygiene/enum.MacroKind.html "enum rustc_span:🪥:MacroKind");

pub use hygiene::[SyntaxContext](hygiene/struct.SyntaxContext.html "struct rustc_span:🪥:SyntaxContext");

pub use symbol::[Ident](symbol/struct.Ident.html "struct rustc_span::symbol::Ident");

pub use symbol::[MacroRulesNormalizedIdent](symbol/struct.MacroRulesNormalizedIdent.html "struct rustc_span::symbol::MacroRulesNormalizedIdent");

pub use symbol::[STDLIB_STABLE_CRATES](symbol/constant.STDLIB%5FSTABLE%5FCRATES.html "constant rustc_span::symbol::STDLIB_STABLE_CRATES");

pub use symbol::[Symbol](symbol/struct.Symbol.html "struct rustc_span::symbol::Symbol");

pub use symbol::[kw](symbol/kw/index.html "mod rustc_span::symbol::kw");

pub use symbol::[sym](symbol/sym/index.html "mod rustc_span::symbol::sym");

analyze_source_file 🔒

caching_source_map_view 🔒

def_id

edit_distance

Edit distances.

edition

fatal_error

hygiene

Machinery for hygienic macros.

profiling

source_map

Types for tracking pieces of source code within a crate.

span_encoding 🔒

symbol

An “interner” is a data structure that associates values with usize tags and allows bidirectional lookup; i.e., given a value, one can easily find the type, and vice versa.

impl_pos 🔒

AttrId

BytePos

A byte offset.

CachingSourceMapView

CharPos

A character offset.

DistinctSources

ErrorGuaranteed

Useful type to use with Result<> indicate that an error has already been reported to the user, so no need to continue checking.

FileLines

FileNameDisplay

InnerSpan

Range inside of a Span used for diagnostics when we only have access to relative positions.

LineInfo

Loc

A source code location used for error reporting.

MalformedSourceMapPositions

MetavarSpansMap

MultiByteChar

Identifies an offset of a multi-byte character in a SourceFile.

NormalizedPos

Identifies an offset of a character that was normalized away from SourceFile.

OffsetOverflowError

RelativeBytePos

A byte offset relative to file beginning.

SessionGlobals

Per-session global variables: this struct is stored in thread-local storage in such a way that it is accessible without any kind of handle to all threads within the compilation session, but is not accessible outside the session.

SourceFile

A single source in the SourceMap.

SourceFileAndBytePos

SourceFileAndLine

SourceFileDiffs

The source file lines in difference list form. This matches the form used within metadata, which saves space by exploiting the fact that the lines list is sorted and individual lines are usually not that long.

SourceFileHash

The hash of the on-disk source file used for debug info and cargo freshness checks.

Span

A compressed span.

SpanData

Represents a span.

StableSourceFileId

This is a SourceFile identifier that is used to correlate source files between subsequent compilation sessions (which is something we need to do during incremental compilation).

ExternalSource

ExternalSourceKind

The state of the lazy external source loading mechanism of a SourceFile.

FileName

Differentiates between real files and common virtual files.

FileNameDisplayPreference

FileNameEmbeddablePreference

RealFileName

SourceFileHashAlgorithm

SourceFileLines

SpanLinesError

SpanSnippetError

DUMMY_SP

The dummy span has zero position, length, and context, and no parent.

SESSION_GLOBALS 🔒

SPAN_TRACK

HashStableContext

Requirements for a StableHashingContext to be used in this crate.

Pos

SpanDecoder

This trait is used to allow decoder specific encodings of certain types. It is similar to rustc_type_ir’s TyDecoder.

SpanEncoder

This trait is used to allow encoder specific encodings of certain types. It is similar to rustc_type_ir’s TyEncoder.

char_width

create_default_session_globals_then

Default edition, no source map.

create_session_globals_then

create_session_if_not_set_then

No source map.

normalize_newlines 🔒

Replaces \r\n with \n in-place in src.

normalize_src 🔒

Normalizes the source code and records the normalizations.

remove_bom 🔒

Removes UTF-8 BOM, if any.

set_session_globals_then

str_width

with_metavar_spans

with_session_globals

FileLinesResult