Function rustc_metadata::creader::import_codemap [] [src]

pub fn import_codemap(local_codemap: &CodeMap, metadata: &MetadataBlob) -> Vec<ImportedFileMap>
Unstable (rustc_private)

Imports the codemap from an external crate into the codemap of the crate currently being compiled (the "local crate").

The import algorithm works analogous to how AST items are inlined from an external crate's metadata: For every FileMap in the external codemap an 'inline' copy is created in the local codemap. The correspondence relation between external and local FileMaps is recorded in the ImportedFileMap objects returned from this function. When an item from an external crate is later inlined into this crate, this correspondence information is used to translate the span information of the inlined item so that it refers the correct positions in the local codemap (see astencode::DecodeContext::tr_span()).

The import algorithm in the function below will reuse FileMaps already existing in the local codemap. For example, even if the FileMap of some source file of libstd gets imported many times, there will only ever be one FileMap object for the corresponding file in the local codemap.

Note that imported FileMaps do not actually contain the source code of the file they represent, just information about length, line breaks, and multibyte characters. This information is enough to generate valid debuginfo for items inlined from other crates.