diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2020-12-07 17:05:28 -0500 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2020-12-08 13:02:53 -0500 |
| commit | a332e2b38fb3c374d751edadfc2c21594f2e7611 (patch) | |
| tree | 25714ffe6bc43feea69425eaac9ac81bc495d12c | |
| parent | afa995b2dd1e194845f2082707e6045d539230a5 (diff) | |
| download | rust-a332e2b38fb3c374d751edadfc2c21594f2e7611.tar.gz rust-a332e2b38fb3c374d751edadfc2c21594f2e7611.zip | |
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()`
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index c571ed7b612..43f7b2a9928 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1553,6 +1553,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { return Some(DefId { krate, index: def_index_guess }); } + let is_proc_macro = self.is_proc_macro_crate(); + // Slow path: We need to find out the new `DefIndex` of the provided // `DefPathHash`, if its still exists. This requires decoding every `DefPathHash` // stored in this crate. @@ -1561,9 +1563,12 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { let mut map = FxHashMap::with_capacity_and_hasher(end_id as usize, Default::default()); for i in 0..end_id { let def_index = DefIndex::from_u32(i); - let hash = - self.root.tables.def_path_hashes.get(self, def_index).unwrap().decode(self); - map.insert(hash, def_index); + // There may be gaps in the encoded table if we're decoding a proc-macro crate + if let Some(hash) = self.root.tables.def_path_hashes.get(self, def_index) { + map.insert(hash.decode(self), def_index); + } else if !is_proc_macro { + panic!("Missing def_path_hashes entry for {:?}", def_index); + } } map }); |
