diff options
| author | Michael Woerister <michaelwoerister@posteo> | 2021-07-20 14:18:37 +0200 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo> | 2021-09-14 13:56:33 +0200 |
| commit | 2b60338ee92fbae7e9414dd1bd6661ccd8a7b9da (patch) | |
| tree | 216ec1bf1acf3a44da1cff6f545c0c903cedfc4b /compiler/rustc_metadata/src | |
| parent | 5445715c20dbedbe9b14d185937ab1ebcd81118e (diff) | |
| download | rust-2b60338ee92fbae7e9414dd1bd6661ccd8a7b9da.tar.gz rust-2b60338ee92fbae7e9414dd1bd6661ccd8a7b9da.zip | |
Make DefPathHash->DefId panic for if the mapping fails.
We only use this mapping for cases where we know that it must succeed. Letting it panic otherwise makes it harder to use the API in unsupported ways.
Diffstat (limited to 'compiler/rustc_metadata/src')
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs | 4 |
3 files changed, 6 insertions, 7 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index d925e3102f2..51a8dcc9db4 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1622,7 +1622,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } #[inline] - fn def_path_hash_to_def_index(&self, hash: DefPathHash) -> Option<DefIndex> { + fn def_path_hash_to_def_index(&self, hash: DefPathHash) -> DefIndex { self.def_path_hash_map.def_path_hash_to_def_index(&hash) } diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 4885de103a0..70952d388d5 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -517,10 +517,9 @@ impl CrateStore for CStore { self.get_crate_data(def.krate).def_path_hash(def.index) } - fn def_path_hash_to_def_id(&self, cnum: CrateNum, hash: DefPathHash) -> Option<DefId> { - self.get_crate_data(cnum) - .def_path_hash_to_def_index(hash) - .map(|index| DefId { krate: cnum, index }) + fn def_path_hash_to_def_id(&self, cnum: CrateNum, hash: DefPathHash) -> DefId { + let def_index = self.get_crate_data(cnum).def_path_hash_to_def_index(hash); + DefId { krate: cnum, index: def_index } } fn expn_hash_to_expn_id(&self, cnum: CrateNum, index_guess: u32, hash: ExpnHash) -> ExpnId { diff --git a/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs b/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs index 3f500fce334..e2095d553f5 100644 --- a/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs +++ b/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs @@ -15,9 +15,9 @@ crate enum DefPathHashMap<'tcx> { impl DefPathHashMap<'tcx> { #[inline] - pub fn def_path_hash_to_def_index(&self, def_path_hash: &DefPathHash) -> Option<DefIndex> { + pub fn def_path_hash_to_def_index(&self, def_path_hash: &DefPathHash) -> DefIndex { match *self { - DefPathHashMap::OwnedFromMetadata(ref map) => map.get(def_path_hash), + DefPathHashMap::OwnedFromMetadata(ref map) => map.get(def_path_hash).unwrap(), DefPathHashMap::BorrowedFromTcx(_) => { panic!("DefPathHashMap::BorrowedFromTcx variant only exists for serialization") } |
