diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /compiler/rustc_hir/src/weak_lang_items.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | compiler/rustc_hir/src/weak_lang_items.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/compiler/rustc_hir/src/weak_lang_items.rs b/compiler/rustc_hir/src/weak_lang_items.rs new file mode 100644 index 000000000..b6a85c047 --- /dev/null +++ b/compiler/rustc_hir/src/weak_lang_items.rs @@ -0,0 +1,47 @@ +//! Validity checking for weak lang items + +use crate::def_id::DefId; +use crate::{lang_items, LangItem, LanguageItems}; + +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 fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol> +{ + lang_items::extract(attrs).and_then(|(name, _)| { + $(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! { + panic_impl, PanicImpl, rust_begin_unwind; + eh_personality, EhPersonality, rust_eh_personality; + eh_catch_typeinfo, EhCatchTypeinfo, rust_eh_catch_typeinfo; + oom, Oom, rust_oom; +} |