Skip to content

Commit a410af9

Browse files
authored
Rollup merge of #79810 - Aaron1011:fix/def-path-table-gap, r=lcnr
Account for gaps in def path table during decoding When encoding a proc-macro crate, there may be gaps in the table (since we only encode the crate root and proc-macro items). Account for this by checking if the entry is present, rather than using `unwrap()`
2 parents 0994f35 + a332e2b commit a410af9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
15531553
return Some(DefId { krate, index: def_index_guess });
15541554
}
15551555

1556+
let is_proc_macro = self.is_proc_macro_crate();
1557+
15561558
// Slow path: We need to find out the new `DefIndex` of the provided
15571559
// `DefPathHash`, if its still exists. This requires decoding every `DefPathHash`
15581560
// stored in this crate.
@@ -1561,9 +1563,12 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
15611563
let mut map = FxHashMap::with_capacity_and_hasher(end_id as usize, Default::default());
15621564
for i in 0..end_id {
15631565
let def_index = DefIndex::from_u32(i);
1564-
let hash =
1565-
self.root.tables.def_path_hashes.get(self, def_index).unwrap().decode(self);
1566-
map.insert(hash, def_index);
1566+
// There may be gaps in the encoded table if we're decoding a proc-macro crate
1567+
if let Some(hash) = self.root.tables.def_path_hashes.get(self, def_index) {
1568+
map.insert(hash.decode(self), def_index);
1569+
} else if !is_proc_macro {
1570+
panic!("Missing def_path_hashes entry for {:?}", def_index);
1571+
}
15671572
}
15681573
map
15691574
});

0 commit comments

Comments
 (0)