Skip to content

Commit

Permalink
Unrolled build for rust-lang#130468
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#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`.
  • Loading branch information
rust-timer authored Sep 18, 2024
2 parents f68c28b + d9624ed commit 9026364
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ impl LanguageItems {

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> {
Expand Down

0 comments on commit 9026364

Please sign in to comment.