From 2b60338ee92fbae7e9414dd1bd6661ccd8a7b9da Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 20 Jul 2021 14:18:37 +0200 Subject: 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. --- compiler/rustc_query_impl/src/on_disk_cache.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'compiler/rustc_query_impl/src') diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index 82cc81ec4c3..f9456a6f2cd 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -361,7 +361,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> { }) } - fn def_path_hash_to_def_id(&self, tcx: TyCtxt<'tcx>, hash: DefPathHash) -> Option { + fn def_path_hash_to_def_id(&self, tcx: TyCtxt<'tcx>, hash: DefPathHash) -> DefId { debug!("def_path_hash_to_def_id({:?})", hash); let stable_crate_id = hash.stable_crate_id(); @@ -369,9 +369,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> { // If this is a DefPathHash from the local crate, we can look up the // DefId in the tcx's `Definitions`. if stable_crate_id == tcx.sess.local_stable_crate_id() { - tcx.definitions_untracked() - .local_def_path_hash_to_def_id(hash) - .map(LocalDefId::to_def_id) + tcx.definitions_untracked().local_def_path_hash_to_def_id(hash).to_def_id() } else { // If this is a DefPathHash from an upstream crate, let the CrateStore map // it to a DefId. @@ -779,12 +777,7 @@ impl<'a, 'tcx> Decodable> for DefId { // If we get to this point, then all of the query inputs were green, // which means that the definition with this hash is guaranteed to // still exist in the current compilation session. - Ok(d.tcx() - .on_disk_cache - .as_ref() - .unwrap() - .def_path_hash_to_def_id(d.tcx(), def_path_hash) - .unwrap()) + Ok(d.tcx().on_disk_cache.as_ref().unwrap().def_path_hash_to_def_id(d.tcx(), def_path_hash)) } } -- cgit 1.4.1-3-g733a5