]> git.proxmox.com Git - rustc.git/blame - src/librustc_hir/weak_lang_items.rs
New upstream version 1.47.0+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
3dfed10e 6use rustc_ast as ast;
74b04a01
XL
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();
3dfed10e 18 $(map.insert(sym::$name, LangItem::$item);)*
74b04a01
XL
19 map
20 };
21}
22
3dfed10e
XL
23/// The `check_name` argument avoids the need for `librustc_hir` to depend on
24/// `librustc_session`.
25pub fn link_name<'a, F>(check_name: F, attrs: &'a [ast::Attribute]) -> Option<Symbol>
26where
27 F: Fn(&'a ast::Attribute, Symbol) -> bool
28{
29 lang_items::extract(check_name, attrs).and_then(|(name, _)| {
74b04a01
XL
30 $(if name == sym::$name {
31 Some(sym::$sym)
32 } else)* {
33 None
34 }
35 })
36}
37
38impl LanguageItems {
39 pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
40 let did = Some(item_def_id);
41
42 $(self.$name() == did)||*
43 }
44}
45
46) }
47
48weak_lang_items! {
3dfed10e
XL
49 panic_impl, PanicImpl, rust_begin_unwind;
50 eh_personality, EhPersonality, rust_eh_personality;
51 oom, Oom, rust_oom;
74b04a01 52}