rust-lang/rust · critical
missing source file
Error message
missing source file
What it means
Fires during source-map import in the decoder (decoder.rs:1811). When a `Span` references a source file by index, the decoder lazily imports it from `root.source_map`; `.expect("missing source file")` panics when the index is absent from the serialized source-map table. The span's `metadata_index` points past the end of the encoded file list.
Source
Thrown at compiler/rustc_metadata/src/rmeta/decoder.rs:1811
*name =
rustc_span::FileName::Real(rustc_span::RealFileName::from_virtual_path(
&virtual_dir.join(subdir).join(rest),
))
}
}
};
let mut import_info = self.source_map_import_info.lock();
for _ in import_info.len()..=(source_file_index as usize) {
import_info.push(None);
}
import_info[source_file_index as usize]
.get_or_insert_with(|| {
let source_file_to_import = self
.root
.source_map
.get(self, source_file_index)
.expect("missing source file")
.decode((self, tcx));
// We can't reuse an existing SourceFile, so allocate a new one
// containing the information we need.
let original_end_pos = source_file_to_import.end_position();
let rustc_span::SourceFile {
mut name,
src_hash,
checksum_hash,
start_pos: original_start_pos,
normalized_source_len,
unnormalized_source_len,
lines,
multibyte_chars,
normalized_pos,
stable_id,
..
} = source_file_to_import;View on GitHub (pinned to 7088e4b63a)
Solutions
- `cargo clean` to rebuild the source-map table consistently with the current spans.
- Ensure debuginfo/remap flags (`--remap-path-prefix`, `-Z simulate-remapped-rust-src-base`) are identical across the build graph.
- For proc-macro crates, rebuild them with the active compiler so their source-map indices line up.
- Clean-build ICE -> report a span/source-map index mismatch.
Defensive patterns
Strategy: validation
Validate before calling
# Keep debuginfo/remap flags identical across the graph so span<->source-map # indices stay consistent. export RUSTFLAGS="--remap-path-prefix=$PWD/=" # identical for every crate export RUSTDOCFLAGS="$RUSTFLAGS" cargo clean && cargo build
Try / catch
cargo build || { cargo clean && cargo build; } Prevention
- Use identical `--remap-path-prefix` and debuginfo flags for every crate in the graph.
- Rebuild proc-macro crates with the active compiler so their source-map indices line up.
- `cargo clean` after changing remap/debuginfo settings.
When it happens
Trigger: A span carrying a `metadata_index` that exceeds the encoded `source_map` array (index/count mismatch between span encoding and source-map encoding); reading proc-macro metadata where source files were not serialized but a span still references them.
Common situations: Remapping/debuginfo options changed between builds while reusing `target/`; proc-macro crate decoded with mismatched `-Z simulate-remapped-rust-src-base` settings; rmeta from a different rustc whose source-map layout differs.
Related errors
- no encoded ident for item
- variants are not encoded for an enum
- provided `DefIndex` must refer to a module-like item
- argument names not encoded for a function
- no parent for a constructor
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/fc5b4871d3da5807.
Report an issue: GitHub.