1 //! Validity checking for weak lang items
3 use crate::def_id::DefId;
4 use crate::{lang_items, LangItem, LanguageItems};
7 use rustc_data_structures::fx::FxIndexMap;
8 use rustc_span::symbol::{sym, Symbol};
10 use std::sync::LazyLock;
12 macro_rules! weak_lang_items {
13 ($($name:ident, $item:ident, $sym:ident;)*) => (
15 pub static WEAK_ITEMS_REFS: LazyLock<FxIndexMap<Symbol, LangItem>> = LazyLock::new(|| {
16 let mut map = FxIndexMap::default();
17 $(map.insert(sym::$name, LangItem::$item);)*
21 pub static WEAK_ITEMS_SYMBOLS: LazyLock<FxIndexMap<LangItem, Symbol>> = LazyLock::new(|| {
22 let mut map = FxIndexMap::default();
23 $(map.insert(LangItem::$item, sym::$sym);)*
27 pub fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol>
29 lang_items::extract(attrs).and_then(|(name, _)| {
30 $(if name == sym::$name {
39 pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
40 let did = Some(item_def_id);
42 $(self.$name() == did)||*
49 panic_impl, PanicImpl, rust_begin_unwind;
50 eh_personality, EhPersonality, rust_eh_personality;
51 eh_catch_typeinfo, EhCatchTypeinfo, rust_eh_catch_typeinfo;