use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
-use rustc_hir::lang_items::{extract, GenericRequirement, ITEM_REFS};
+use rustc_hir::lang_items::{extract, GenericRequirement};
use rustc_hir::{HirId, LangItem, LanguageItems, Target};
use rustc_middle::ty::TyCtxt;
use rustc_session::cstore::ExternCrate;
fn check_for_lang(&mut self, actual_target: Target, hir_id: HirId) {
let attrs = self.tcx.hir().attrs(hir_id);
if let Some((name, span)) = extract(&attrs) {
- match ITEM_REFS.get(&name).cloned() {
+ match LangItem::from_name(name) {
// Known lang item with attribute on correct target.
- Some((item_index, expected_target)) if actual_target == expected_target => {
- self.collect_item_extended(item_index, hir_id, span);
+ Some(lang_item) if actual_target == lang_item.target() => {
+ self.collect_item_extended(lang_item, hir_id, span);
}
// Known lang item with attribute on incorrect target.
- Some((_, expected_target)) => {
+ Some(lang_item) => {
self.tcx.sess.emit_err(LangItemOnIncorrectTarget {
span,
name,
- expected_target,
+ expected_target: lang_item.target(),
actual_target,
});
}
}
}
- fn collect_item(&mut self, item_index: usize, item_def_id: DefId) {
+ fn collect_item(&mut self, lang_item: LangItem, item_def_id: DefId) {
// Check for duplicates.
- if let Some(original_def_id) = self.items.items[item_index] {
+ if let Some(original_def_id) = self.items.get(lang_item) {
if original_def_id != item_def_id {
let local_span = self.tcx.hir().span_if_local(item_def_id);
- let lang_item_name = LangItem::from_u32(item_index as u32).unwrap().name();
+ let lang_item_name = lang_item.name();
let crate_name = self.tcx.crate_name(item_def_id.krate);
let mut dependency_of = Empty;
let is_local = item_def_id.is_local();
}
// Matched.
- self.items.items[item_index] = Some(item_def_id);
- if let Some(group) = LangItem::from_u32(item_index as u32).unwrap().group() {
- self.items.groups[group as usize].push(item_def_id);
- }
+ self.items.set(lang_item, item_def_id);
}
// Like collect_item() above, but also checks whether the lang item is declared
// with the right number of generic arguments.
- fn collect_item_extended(&mut self, item_index: usize, hir_id: HirId, span: Span) {
+ fn collect_item_extended(&mut self, lang_item: LangItem, hir_id: HirId, span: Span) {
let item_def_id = self.tcx.hir().local_def_id(hir_id).to_def_id();
- let lang_item = LangItem::from_u32(item_index as u32).unwrap();
let name = lang_item.name();
// Now check whether the lang_item has the expected number of generic
}
}
- self.collect_item(item_index, item_def_id);
+ self.collect_item(lang_item, item_def_id);
}
}
// Collect lang items in other crates.
for &cnum in tcx.crates(()).iter() {
- for &(def_id, item_index) in tcx.defined_lang_items(cnum).iter() {
- collector.collect_item(item_index, def_id);
+ for &(def_id, lang_item) in tcx.defined_lang_items(cnum).iter() {
+ collector.collect_item(lang_item, def_id);
}
}
let item = tcx.hir().item(id);
if let hir::ItemKind::Enum(def, ..) = &item.kind {
for variant in def.variants {
- collector.check_for_lang(Target::Variant, variant.id);
+ collector.check_for_lang(Target::Variant, variant.hir_id);
}
}
}