Expand description
Source positions and related helper functions.
Important concepts in this module include:
- the span, represented by
SpanData
and related types; - source code as represented by a
SourceMap
; and - interned strings, represented by
Symbol
s, with some common symbols available statically in thesym
module.
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 in
SyntaxContext
and ExpnData
.
§Note
This API is completely unstable and subject to change.
Re-exports§
pub use hygiene::DesugaringKind;
pub use hygiene::ExpnData;
pub use hygiene::ExpnHash;
pub use hygiene::ExpnId;
pub use hygiene::ExpnKind;
pub use hygiene::LocalExpnId;
pub use hygiene::MacroKind;
pub use hygiene::SyntaxContext;
pub use symbol::Ident;
pub use symbol::MacroRulesNormalizedIdent;
pub use symbol::STDLIB_STABLE_CRATES;
pub use symbol::Symbol;
pub use symbol::kw;
pub use symbol::sym;
Modules§
- 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.
Macros§
- impl_
pos 🔒
Structs§
- AttrId
- BytePos
- A byte offset.
- Caching
Source MapView - CharPos
- A character offset.
- Distinct
Sources - Error
Guaranteed - Useful type to use with
Result<>
indicate that an error has already been reported to the user, so no need to continue checking. - File
Lines - File
Name Display - Inner
Span - Range inside of a
Span
used for diagnostics when we only have access to relative positions. - Line
Info - Loc
- A source code location used for error reporting.
- Malformed
Source MapPositions - Metavar
Spans Map - Multi
Byte Char - Identifies an offset of a multi-byte character in a
SourceFile
. - Normalized
Pos - Identifies an offset of a character that was normalized away from
SourceFile
. - Offset
Overflow Error - Relative
Byte Pos - A byte offset relative to file beginning.
- Session
Globals - 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.
- Source
File - A single source in the
SourceMap
. - Source
File AndByte Pos - Source
File AndLine - Source
File Diffs - 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.
- Source
File Hash - The hash of the on-disk source file used for debug info and cargo freshness checks.
- Span
- A compressed span.
- Span
Data - Represents a span.
- Stable
Source File Id - 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).
Enums§
- External
Source - External
Source Kind - The state of the lazy external source loading mechanism of a
SourceFile
. - File
Name - Differentiates between real files and common virtual files.
- File
Name Display Preference - Real
File Name - Source
File Hash Algorithm - Source
File Lines - Span
Lines Error - Span
Snippet Error
Constants§
- DUMMY_
SP - The dummy span has zero position, length, and context, and no parent.
Statics§
Traits§
- Hash
Stable Context - Requirements for a
StableHashingContext
to be used in this crate. - Pos
- Span
Decoder - This trait is used to allow decoder specific encodings of certain types. It is similar to rustc_type_ir’s TyDecoder.
- Span
Encoder - This trait is used to allow encoder specific encodings of certain types. It is similar to rustc_type_ir’s TyEncoder.
Functions§
- 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 insrc
. - 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