|
1 | 1 | //! Validity checking for weak lang items |
2 | 2 |
|
3 | | -use crate::def_id::DefId; |
4 | | -use crate::{lang_items, LangItem, LanguageItems}; |
| 3 | +use crate::LangItem; |
5 | 4 |
|
6 | | -use rustc_ast as ast; |
7 | | -use rustc_data_structures::fx::FxIndexMap; |
8 | 5 | use rustc_span::symbol::{sym, Symbol}; |
9 | 6 |
|
10 | | -use std::sync::LazyLock; |
11 | | - |
12 | 7 | macro_rules! weak_lang_items { |
13 | | - ($($name:ident, $item:ident, $sym:ident;)*) => ( |
14 | | - |
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);)* |
18 | | - map |
19 | | -}); |
20 | | - |
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);)* |
24 | | - map |
25 | | -}); |
26 | | - |
27 | | -pub fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol> |
28 | | -{ |
29 | | - lang_items::extract(attrs).and_then(|(name, _)| { |
30 | | - $(if name == sym::$name { |
31 | | - Some(sym::$sym) |
32 | | - } else)* { |
33 | | - None |
| 8 | + ($($item:ident, $sym:ident;)*) => { |
| 9 | + pub static WEAK_LANG_ITEMS: &[LangItem] = &[$(LangItem::$item,)*]; |
| 10 | + |
| 11 | + impl LangItem { |
| 12 | + pub fn is_weak(self) -> bool { |
| 13 | + matches!(self, $(LangItem::$item)|*) |
| 14 | + } |
| 15 | + |
| 16 | + pub fn link_name(self) -> Option<Symbol> { |
| 17 | + match self { |
| 18 | + $( LangItem::$item => Some(sym::$sym),)* |
| 19 | + _ => None, |
| 20 | + } |
| 21 | + } |
34 | 22 | } |
35 | | - }) |
36 | | -} |
37 | | - |
38 | | -impl 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 | 23 | } |
44 | 24 | } |
45 | 25 |
|
46 | | -) } |
47 | | - |
48 | 26 | weak_lang_items! { |
49 | | - panic_impl, PanicImpl, rust_begin_unwind; |
50 | | - eh_personality, EhPersonality, rust_eh_personality; |
51 | | - eh_catch_typeinfo, EhCatchTypeinfo, rust_eh_catch_typeinfo; |
52 | | - oom, Oom, rust_oom; |
| 27 | + PanicImpl, rust_begin_unwind; |
| 28 | + EhPersonality, rust_eh_personality; |
| 29 | + EhCatchTypeinfo, rust_eh_catch_typeinfo; |
| 30 | + Oom, rust_oom; |
53 | 31 | } |
0 commit comments