2020-01-26 13:16:02 +01:00
|
|
|
//! Validity checking for weak lang items
|
|
|
|
|
2020-01-30 01:24:51 +01:00
|
|
|
use crate::def_id::DefId;
|
2020-01-26 13:16:02 +01:00
|
|
|
use crate::{lang_items, LangItem, LanguageItems};
|
|
|
|
|
2020-04-27 23:26:11 +05:30
|
|
|
use rustc_ast as ast;
|
2020-01-26 13:16:02 +01:00
|
|
|
use rustc_data_structures::fx::FxHashMap;
|
|
|
|
use rustc_span::symbol::{sym, Symbol};
|
|
|
|
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
|
|
|
macro_rules! weak_lang_items {
|
|
|
|
($($name:ident, $item:ident, $sym:ident;)*) => (
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
pub static ref WEAK_ITEMS_REFS: FxHashMap<Symbol, LangItem> = {
|
|
|
|
let mut map = FxHashMap::default();
|
2020-08-18 11:47:27 +01:00
|
|
|
$(map.insert(sym::$name, LangItem::$item);)*
|
2020-01-26 13:16:02 +01:00
|
|
|
map
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-07 11:11:44 +10:00
|
|
|
/// The `check_name` argument avoids the need for `librustc_hir` to depend on
|
|
|
|
/// `librustc_session`.
|
|
|
|
pub fn link_name<'a, F>(check_name: F, attrs: &'a [ast::Attribute]) -> Option<Symbol>
|
|
|
|
where
|
|
|
|
F: Fn(&'a ast::Attribute, Symbol) -> bool
|
|
|
|
{
|
|
|
|
lang_items::extract(check_name, attrs).and_then(|(name, _)| {
|
2020-01-26 13:16:02 +01:00
|
|
|
$(if name == sym::$name {
|
|
|
|
Some(sym::$sym)
|
|
|
|
} else)* {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LanguageItems {
|
|
|
|
pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
|
|
|
|
let did = Some(item_def_id);
|
|
|
|
|
|
|
|
$(self.$name() == did)||*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
) }
|
|
|
|
|
|
|
|
weak_lang_items! {
|
2020-08-18 11:47:27 +01:00
|
|
|
panic_impl, PanicImpl, rust_begin_unwind;
|
|
|
|
eh_personality, EhPersonality, rust_eh_personality;
|
2020-03-21 07:50:38 +00:00
|
|
|
eh_catch_typeinfo, EhCatchTypeinfo, rust_eh_catch_typeinfo;
|
2020-08-18 11:47:27 +01:00
|
|
|
oom, Oom, rust_oom;
|
2020-01-26 13:16:02 +01:00
|
|
|
}
|