]> git.proxmox.com Git - rustc.git/blame - src/librustc_hir/weak_lang_items.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / librustc_hir / weak_lang_items.rs
CommitLineData
74b04a01
XL
1//! Validity checking for weak lang items
2
3use crate::def_id::DefId;
4use crate::{lang_items, LangItem, LanguageItems};
5
6use rustc_ast::ast;
7use rustc_data_structures::fx::FxHashMap;
8use rustc_span::symbol::{sym, Symbol};
9
10use lazy_static::lazy_static;
11
12macro_rules! weak_lang_items {
13 ($($name:ident, $item:ident, $sym:ident;)*) => (
14
15lazy_static! {
16 pub static ref WEAK_ITEMS_REFS: FxHashMap<Symbol, LangItem> = {
17 let mut map = FxHashMap::default();
18 $(map.insert(sym::$name, lang_items::$item);)*
19 map
20 };
21}
22
23pub fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol> {
24 lang_items::extract(attrs).and_then(|(name, _)| {
25 $(if name == sym::$name {
26 Some(sym::$sym)
27 } else)* {
28 None
29 }
30 })
31}
32
33impl LanguageItems {
34 pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
35 let did = Some(item_def_id);
36
37 $(self.$name() == did)||*
38 }
39}
40
41) }
42
43weak_lang_items! {
44 panic_impl, PanicImplLangItem, rust_begin_unwind;
45 eh_personality, EhPersonalityLangItem, rust_eh_personality;
74b04a01
XL
46 oom, OomLangItem, rust_oom;
47}