diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
commit | 4547b622d8d29df964fa2914213088b148c498fc (patch) | |
tree | 9fc6b25f3c3add6b745be9a2400a6e96140046e9 /compiler/rustc_hir/src/weak_lang_items.rs | |
parent | Releasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz rustc-4547b622d8d29df964fa2914213088b148c498fc.zip |
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_hir/src/weak_lang_items.rs')
-rw-r--r-- | compiler/rustc_hir/src/weak_lang_items.rs | 59 |
1 files changed, 18 insertions, 41 deletions
diff --git a/compiler/rustc_hir/src/weak_lang_items.rs b/compiler/rustc_hir/src/weak_lang_items.rs index da9c9c121..0cc50c6dd 100644 --- a/compiler/rustc_hir/src/weak_lang_items.rs +++ b/compiler/rustc_hir/src/weak_lang_items.rs @@ -1,53 +1,30 @@ //! Validity checking for weak lang items -use crate::def_id::DefId; -use crate::{lang_items, LangItem, LanguageItems}; +use crate::LangItem; -use rustc_ast as ast; -use rustc_data_structures::fx::FxIndexMap; use rustc_span::symbol::{sym, Symbol}; -use std::sync::LazyLock; - macro_rules! weak_lang_items { - ($($name:ident, $item:ident, $sym:ident;)*) => ( - -pub static WEAK_ITEMS_REFS: LazyLock<FxIndexMap<Symbol, LangItem>> = LazyLock::new(|| { - let mut map = FxIndexMap::default(); - $(map.insert(sym::$name, LangItem::$item);)* - map -}); - -pub static WEAK_ITEMS_SYMBOLS: LazyLock<FxIndexMap<LangItem, Symbol>> = LazyLock::new(|| { - let mut map = FxIndexMap::default(); - $(map.insert(LangItem::$item, sym::$sym);)* - map -}); - -pub fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol> -{ - lang_items::extract(attrs).and_then(|(name, _)| { - $(if name == sym::$name { - Some(sym::$sym) - } else)* { - None + ($($item:ident, $sym:ident;)*) => { + pub static WEAK_LANG_ITEMS: &[LangItem] = &[$(LangItem::$item,)*]; + + impl LangItem { + pub fn is_weak(self) -> bool { + matches!(self, $(LangItem::$item)|*) + } + + pub fn link_name(self) -> Option<Symbol> { + match self { + $( LangItem::$item => Some(sym::$sym),)* + _ => 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! { - panic_impl, PanicImpl, rust_begin_unwind; - eh_personality, EhPersonality, rust_eh_personality; - eh_catch_typeinfo, EhCatchTypeinfo, rust_eh_catch_typeinfo; - oom, Oom, rust_oom; + PanicImpl, rust_begin_unwind; + EhPersonality, rust_eh_personality; + EhCatchTypeinfo, rust_eh_catch_typeinfo; } |