Rollup merge of #130468 - compiler-errors:bidi, r=Nadrieril

Make sure that def id <=> lang item map is bidirectional

Self-explanatory from assertion. Just makes sure of an invariant that I forgot to enforce when I added `LanguageItems::from_def_id`.
This commit is contained in:
Matthias Krüger 2024-09-18 09:03:53 +02:00 committed by GitHub
commit 7e67d90213
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,7 +45,16 @@ pub fn get(&self, item: LangItem) -> Option<DefId> {
pub fn set(&mut self, item: LangItem, def_id: DefId) {
self.items[item as usize] = Some(def_id);
self.reverse_items.insert(def_id, item);
let preexisting = self.reverse_items.insert(def_id, item);
// This needs to be a bijection.
if let Some(preexisting) = preexisting {
panic!(
"For the bijection of LangItem <=> DefId to work,\
one item DefId may only be assigned one LangItem. \
Separate the LangItem definitions for {item:?} and {preexisting:?}."
);
}
}
pub fn from_def_id(&self, def_id: DefId) -> Option<LangItem> {