Skip to main content

Crate rustc_span

Crate rustc_span 

Source
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 Symbols, with some common symbols available statically in the sym 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(crate) use source_map::SourceMap; πŸ”’
pub(crate) use source_map::SourceMapInputs; πŸ”’
pub use self::caching_source_map_view::CachingSourceMapView;
pub(crate) use crate::def_id::DefPathHash; πŸ”’
pub(crate) use crate::fatal_error::FatalError; πŸ”’
pub(crate) use edition::Edition; πŸ”’
pub(crate) use hygiene::Transparency; πŸ”’
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(crate) use def_id::CrateNum; πŸ”’
pub(crate) use def_id::DefId; πŸ”’
pub(crate) use def_id::DefIndex; πŸ”’
pub(crate) use def_id::LOCAL_CRATE; πŸ”’
pub(crate) use def_id::LocalDefId; πŸ”’
pub(crate) use def_id::StableCrateId; πŸ”’
pub use span_encoding::DUMMY_SP;
pub use span_encoding::OrdSpan;
pub use span_encoding::Span;
pub use symbol::ByteSymbol;
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;
pub use macros::bug;
pub use macros::span_bug;
pub(crate) use span_encoding::InlineCtxt; πŸ”’
pub(crate) use DummyStableHashCtxt; πŸ”’
pub(crate) use StableHashCtxt; πŸ”’
pub(crate) use AtomicRef; πŸ”’
pub(crate) use outline; πŸ”’
pub(crate) use Decodable; πŸ”’
pub(crate) use Encodable; πŸ”’
pub(crate) use StableHash; πŸ”’
pub(crate) use rustc_serialize::opaque::mem_encoder::MemEncoder; πŸ”’
pub(crate) use FileEncoder; πŸ”’
pub(crate) use MemDecoder; πŸ”’
pub(crate) use Decodable; πŸ”’
pub(crate) use Decoder; πŸ”’
pub(crate) use Encodable; πŸ”’
pub(crate) use Encoder; πŸ”’
pub(crate) use tracing::debug; πŸ”’
pub(crate) use std::borrow::Cow; πŸ”’
pub(crate) use std::fmt::Display; πŸ”’
pub(crate) use std::hash::Hash; πŸ”’
pub(crate) use std::hash::Hash; πŸ”’
pub(crate) use io; πŸ”’
pub(crate) use Read; πŸ”’
pub(crate) use Add; πŸ”’
pub(crate) use Range; πŸ”’
pub(crate) use Sub; πŸ”’
pub(crate) use Path; πŸ”’
pub(crate) use PathBuf; πŸ”’
pub(crate) use std::str::FromStr; πŸ”’
pub(crate) use std::sync::Arc; πŸ”’
pub(crate) use cmp; πŸ”’
pub(crate) use fmt; πŸ”’
pub(crate) use iter; πŸ”’
pub(crate) use Digest; πŸ”’
pub(crate) use Md5; πŸ”’
pub(crate) use StableHash; πŸ”’
pub(crate) use StableHasher; πŸ”’
pub(crate) use FreezeLock; πŸ”’
pub(crate) use FreezeWriteGuard; πŸ”’
pub(crate) use Lock; πŸ”’
pub(crate) use rustc_data_structures::unord::UnordMap; πŸ”’
pub(crate) use Hash64; πŸ”’
pub(crate) use Hash128; πŸ”’
pub(crate) use sha1::Sha1; πŸ”’
pub(crate) use sha2::Sha256; πŸ”’

ModulesΒ§

analyze_source_file πŸ”’
caching_source_map_view πŸ”’
def_id
edit_distance
Edit distances.
edition
fatal_error
hygiene
Machinery for hygienic macros.
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.
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
InnerRealFileName πŸ”’
The inner workings of RealFileName.
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
RealFileName
A self-contained β€œreal” filename.
RelativeBytePos
A byte offset relative to file beginning.
RemapPathScopeComponents
Scopes used to determined if it need to apply to --remap-path-prefix
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.
SpanData
Represents a span.
Spanned
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).

EnumsΒ§

ExternalSource
ExternalSourceKind
The state of the lazy external source loading mechanism of a SourceFile.
FileName
Differentiates between real files and common virtual files.
FileNameDisplayPreference πŸ”’
SourceFileHashAlgorithm
SourceFileLines
SpanLinesError
SpanSnippetError

ConstantsΒ§

UNICODE_VERSION
The version of Unicode that this version of unicode-width is based on.

StaticsΒ§

SESSION_GLOBALS πŸ”’
SPAN_TRACK

TraitsΒ§

BlobDecoder
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.

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.
dummy_spanned
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.
respan
set_session_globals_then
str_width
with_metavar_spans
with_session_globals

Type AliasesΒ§

FileLinesResult