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.
This commit is contained in:
parent
5445715c20
commit
2b60338ee9
8 changed files with 18 additions and 25 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue